function valid_ca_phone_number in Phone 5
Same name and namespace in other branches
- 6 phone.ca.inc \valid_ca_phone_number()
- 7 include/phone.ca.inc \valid_ca_phone_number()
Verifies that $phonenumber is a valid ten-digit North American phone number
Parameters
string $phonenumber:
Return value
boolean Returns boolean FALSE if the phone number is not valid.
File
- ./
phone.ca.inc, line 10
Code
function valid_ca_phone_number($phonenumber) {
//$phonenumber = trim($phonenumber);
// define regular expression
$regex = "/\n \\D* # ignore non-digits\n 1? # an optional 1\n \\D* # optional separator \n [02-9]\\d{2} # area code (can't start with 1)\n \\D* # optional separator\n \\d{3} # 3-digit prefix\n \\D* # optional separator\n \\d{4} # 4-digit line number\n \\D* # optional separator\n \\d* # optional extension\n \\D* # ignore trailing non-digits\n /x";
// return true if valid, false otherwise
return (bool) preg_match($regex, $phonenumber);
}