I'm using vdaemon (http://www.x-code.com/vdaemon_dreamweaver_extension.php) extension for dreamweaver to validate form fields.
This is the general format for the validation of a name field:

regexp="|\A[A-Za-z'\s]*\z|"

I need to create a regexp to check the validity of telephone numbers that might include the numbers 0-9 aswell as the possibility of round brackets
Would really appreciate any help.

NOTE: This is for UK phone numbers which have the following format: (01111) 123123

Thanks a lot.

    I'm from the UK and that's definitely not the format of my home number although it's the same number of digits.

    Are you also taking into consideration the +44 (0) 123 1234123?

    Can't help you much with regexps but try this site;
    http://www.regexlib.com/

    Good bookmark.

      Hi SeenGee,

      UK landline and mobile phone numbers are ten characters long without country code, leading zeros, commas and other garb.

      The first four digits after the country code and leading zero are the network or geographic code, the six digits after that are the terminating number or DDI.

      This might help:

      // get rid of the crap: leading zeros, uk country code, brackets and hypens
      
      $number= ereg_replace("^0","",$number);
      $number= ereg_replace("^44","",$number);
      $number= ereg_replace("\(","",$number);
      $number= ereg_replace("\)","",$number);
      $number= ereg_replace("-","",$number);
      
      // check it is a valid number of the right length
      if((preg_match("/[^0-9\(\)\(\)\. ]/", $number)) or (strlen($number)!="10")){ 
      
      echo "Bad number";
      
      }else{
      
      // number is okay
      
      // extract the area or network code
      $code = substr("$number", 0, 4);
      
      // extract the destimation number
      $ddi = substr("$number", 4, 6);
      
      // package it back together and bingo
      $number = "44 (0) $code $ddi";
      echo "$number";
      
      }

      If you wanted to take it a step further you can download files of numbers from Oftel which tell you more about the network / area code, like what mobile network or town......

      http://www.oftel.gov.uk/ind_info/numbering/download.htm

      Tis Crown Copyright so use it mischeviously and they'll throw you in the tower of London..... and no you can't blame me 😉

      Hope it helps

        Write a Reply...