looking for UK phone validator class
Moderator: General Moderators
looking for UK phone validator class
i'm looking for a simple php class that i can use to validate UK phone numbers
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Try:
Where $num is the phone number.
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';
}thanks, one more question
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?
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?
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.
I've no idea how you go about validating mobile numbers as i'm not sure of all the operator specific numbers.