function valid_gb_phone_number in Phone 7
Same name and namespace in other branches
- 6 phone.gb.inc \valid_gb_phone_number()
Verifies that $phonenumber is a valid eleven-digit United Kingdom phone number
Regular expression adapted from Amos Hurd's regex at RegExLib.com
Parameters
string $phonenumber:
Return value
boolean Returns boolean FALSE if the phone number is not valid.
File
- include/
phone.gb.inc, line 24 - CCK Field for British phone numbers.
Code
function valid_gb_phone_number($phonenumber) {
/*
Accepts:
+441970123456
+44(0)1970123456
+44 1970 123 456
+44 (0)1970 123 456
(01970) 123456 #0001
Rejects:
(+441970)123456
+44(1970)123456
+44 01970 123 456
(0197) 0123456 #01
*/
$regex = "/\n (\n (^\\+44\\s?(\\(0\\))?\\d{4}|^\\(?0\\d{4}\\)?){1}\\s?\\d{3}\\s?\\d{3} # 4 digit area code with optional +44 internationalisation or not, optional spaces and brackets.\n |\n (^\\+44\\s?(\\(0\\))?\\d{3}|^\\(?0\\d{3}\\)?){1}\\s?\\d{3}\\s?\\d{4} # 3 digit area code with optional +44 internationalisation or not, optional spaces and brackets.\n |\n (^\\+44\\s?(\\(0\\))?\\d{2}|^\\(?0\\d{2}\\)?){1}\\s?\\d{4}\\s?\\d{4} # 2 digit area code with optional +44 internationalisation or not, optional spaces and brackets.\n |\n (^\\+44\\s?(\\(0\\))?\\d{1}|^\\(?0\\d{1}\\)?){1}\\s?\\d{5}\\s?\\d{5} # 1 digit area code with optional +44 internationalisation or not, optional spaces and brackets. \n )\n (\\s?\\#\\d*)? # optional extension number shown with a hash divider\n /x";
if (!preg_match($regex, $phonenumber)) {
return FALSE;
}
else {
return TRUE;
}
}