Jump to content

Telephone Number Validation


chile
 Share

Recommended Posts

It will probably be easiest to use a regular expression. There are several regular expression patterns for matching telephone numbers online:http://www.google.com/search?client=opera&...-8&oe=utf-8Once you find the pattern you want to use, the PHP function to use is preg_match.
thanx, i have tried most of them. will check it again and let you know how i go. thanx anyway
Link to comment
Share on other sites

Wy should you bother validating a phone number? Because they could easily just give away someone else his number? The only way to really validate this is just to call the person. And besides wy not let people choose if they want to give their phone-number if they have that choice they would not be entering invalid phone-numbers.

Link to comment
Share on other sites

Validation in this context usually means deciding if the format is correct, not if the name, address, or phone number belongs to an actual person. We have all been trained as children to write phone numbers by hand with blank spaces, dashes, parentheses, and other non-numerical characters. But since we all do it differently, especially when we consider international numbers, then we must check the format. This is mostly for the convenience of the user, who may wish to be contacted by phone if something goes wrong.One way to do this is to require that users only enter digits, and then ask them to correct the entry if they have entered anything else. This requires a way to screen for non-numerical characters.

Link to comment
Share on other sites

Or you could just get all numbers, and leave out everything else:

preg_match_all('/[0-9]/', str_replace('+', '00', $_GET['phone']), $digits);$phone = implode($digits[0]);

So that:+35932696969+35932/69 69 69+359 (32) 69 69 6900 359 32 696 96900 35932 69-69-69+ 35932 696-969(+359) 32 69 69 69are all turned into:0035932696969And if you're more into using "+" instead of leading "00", you can turn those back into "+", like so:

$phone = preg_replace('/^00/', '+', $phone);

P.S. I haven't tried those out, so there may be errors in my regular expressions. It should still go as something similar.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...