function valid_ua_phone_number in Phone 6
Same name and namespace in other branches
- 7 include/phone.ua.inc \valid_ua_phone_number()
Verifies that $phonenumber is valid
Parameters
string $phonenumber:
Return value
boolean Returns boolean FALSE if the phone number is not valid.
File
- ./
phone.ua.inc, line 544 - CCK Field for Ukrainian phone numbers.
Code
function valid_ua_phone_number($phonenumber) {
// For adressing Ukraine phones used both +38 and +380 as a prefix.
// So lets clean up any spaces, pareenthesis, minus signs etc first.
$cleaning_pattern = '/( |\\-|\\(|\\))*/';
$refined_phonenumber = preg_replace($cleaning_pattern, '', $phonenumber);
// define regular expression
$code_packs = _phone_ua_get_valid_masks();
foreach ($code_packs as $codes) {
// $regex = "/^((8|\+38)-?)?\s*(\(?044\)?)?-?\d{3}-?\d{2}-?\d{2}$/i";
// Please note - pure 8 as a prefix is obsolete.
$regex = "/^(\\+38)?0(" . $codes . ")\$/";
if (preg_match($regex, $refined_phonenumber)) {
return true;
}
}
// return true if valid, false otherwise
return false;
}