Phone Number Validation
Moderator: General Moderators
- seodevhead
- Forum Regular
- Posts: 705
- Joined: Sat Oct 08, 2005 8:18 pm
- Location: Windermere, FL
Phone Number Validation
Hey guys, was wondering if anyone had any particular code suggestions for validating phone numbers.. reg ex's, etc. Have been looking around without luck. Thanks and take care!
Code: Select all
#http://www.owasp.org/software/validation.html
/*
phone
^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$
US phone number with or without dashes
*/
function isPhoneNumber($phn){
if (preg_match ("/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/", $phn))
return TRUE;
else
return FALSE;
}- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Yep... If you're going to do this w/out <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> your visitors off then it will have to be very very loose checking. You could provide fixed-length input boxes for them to type in too... that would make it clearer what is expected to be used.