chile Posted March 25, 2009 Share Posted March 25, 2009 hi guys, can anyone tell me how to validate telephone number in php please Link to comment Share on other sites More sharing options...
justsomeguy Posted March 25, 2009 Share Posted March 25, 2009 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. Link to comment Share on other sites More sharing options...
chile Posted March 26, 2009 Author Share Posted March 26, 2009 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 More sharing options...
vytas Posted March 26, 2009 Share Posted March 26, 2009 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 More sharing options...
jeffman Posted March 26, 2009 Share Posted March 26, 2009 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 More sharing options...
boen_robot Posted March 27, 2009 Share Posted March 27, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.