You are here

function valid_ph_phone_number in Phone 6

Same name and namespace in other branches
  1. 7 include/phone.ph.inc \valid_ph_phone_number()

Verifies that $phonenumber is a valid ten-digit Philippine phone number

Parameters

string $phonenumber:

Return value

boolean Returns boolean FALSE if the phone number is not valid.

File

./phone.ph.inc, line 23
CCK Field for Philippine phone numbers.

Code

function valid_ph_phone_number($phonenumber) {

  /*
    Accepts:
        +63197071234567
  				+63197071234567
        +63(19707) 1234567
  				+63(19707) 123-4567
        +63 19707 123 4567
        +63 19707 123-4567
        (19707) 1234567 loc. 1234
  */
  $regex = "/\n    (\n        (^\\+63\\s?\\(?\\d{5}\\)?|^\\(?\\d{5}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}  # 5 digit area code with optional +63 internationalisation or not, optional spaces and brackets.\n        |\n        (^\\+63\\s?\\(?\\d{4}\\)?|^\\(?\\d{4}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}  # 4 digit area code with optional +63 internationalisation or not, optional spaces and brackets.\n        |\n        (^\\+63\\s?\\(?\\d{3}\\)?|^\\(?\\d{3}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}  # 3 digit area code with optional +63 internationalisation or not, optional spaces and brackets.\n        |\n        (^\\+63\\s?\\(?\\d{2}\\)?|^\\(?\\d{2}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}  # 2 digit area code with optional +63 internationalisation or not, optional spaces and brackets.\n        |\n        (^\\+63\\s?\\(?\\d{1}\\)?|^\\(?\\d{1}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}  # 1 digit area code with optional +63 internationalisation or not, optional spaces and brackets.\n    )\n    (\\s?\\#\\d*)?   # optional extension number shown with a loc. divider\n  /x";

  // return true if valid, false otherwise
  if (!preg_match($regex, $phonenumber)) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}