function valid_uk_phone_number in Phone 5
File
- ./
phone.uk.inc, line 28
Code
function valid_uk_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 (\\s?\\#\\d*)? # optional extension number shown with a hash divider\n /x";
if (!preg_match($regex, $phonenumber)) {
return false;
}
else {
return true;
}
}