View Full Version : Phone form validification question aimed to canadians

08-22-2004, 05:30 AM
Hey, I found this php phone number verification script, and would like to know if this would work for canadian users as well. Since I don't personally know anyone in Canada I can't call them up to ask, and even if I could, they prob wouldnt know if it would work. So I came to ask you :D .

Anyways the script is :

function VALIDATE_USPHONE($phonenumber,$useareacode=true)
if ( preg_match("/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/",$phonenumber) || (preg_match("/^[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/",$phonenumber) && !$useareacode)) return eregi_replace("[^0-9]", "", $phonenumber);
return false;

and was found here (http://codewalkers.com/tutorials/47/8.html) , The site says "US numbers" however I don't know if it can work for both.

Thanks for your help guys :)

08-22-2004, 08:12 PM
I've lived in canada before and by the looks of that regex it's just checking for numbers.. which doesn't mean it is necessarily a 'valid' phone number and since candada's phone number formatting is the same as the US' it should work.

08-22-2004, 08:16 PM
Perfect :) thank you