Page 1 of 1
looking for UK phone validator class
Posted: Thu Jun 17, 2004 1:00 am
by MrGreen
i'm looking for a simple php class that i can use to validate UK phone numbers
Posted: Thu Jun 17, 2004 11:54 am
by John Cartwright
Show us a valid phone number?
Posted: Thu Jun 17, 2004 12:01 pm
by markl999
Try:
Code: Select all
if(preg_match("!^(44[ ]?)?[0-9]{3,5}[ ]?[0-9]{3}[ ]?[0-9]{3,4}$!", trim(preg_replace("!\\s{1,}!", " ", str_replace("+", "", str_replace("(", "", str_replace(")", "", $num))))), $matches)){
echo 'Valid Number';
} else {
echo 'Invalid Number';
}
Where $num is the phone number.
thanks, one more question
Posted: Thu Jun 17, 2004 12:38 pm
by MrGreen
this is valid only for regular phone number, right?
do you have an example of a valid number that i can test it with?
is there an adition that i can use that can work for cellular numbers also?
Posted: Thu Jun 17, 2004 12:43 pm
by markl999
Yeah, it's only valid for UK numbers (see
http://www.wtng.info/wtng-uu.html#United%20Kingdom for the format).
I've no idea how you go about validating mobile numbers as i'm not sure of all the operator specific numbers.