You are here

function valid_es_phone_number in Phone 7

Same name and namespace in other branches
  1. 5 phone.es.inc \valid_es_phone_number()
  2. 6 phone.es.inc \valid_es_phone_number()

Verifies that $phonenumber is a valid nine-digit Spanish phone number

Parameters

string $phonenumber:

Return value

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

File

include/phone.es.inc, line 22
CCK Field for Spanish phone numbers.

Code

function valid_es_phone_number($phonenumber) {
  $phonenumber = trim($phonenumber);

  // define regular expression

  //$regex = "/

  //  \D*           # optional separator
  //  [69]\d{2}     # first group of numbers
  //  \D*           # optional separator
  //  \d{3}         # second group
  //  \D*           # optional separator
  //  \d{3}         # third group
  //  \D*           # ignore trailing non-digits
  //  $/x";
  $regex = '/^[0-9]{2,3}-? ?[0-9]{6,7}$/';

  // return true if valid, false otherwise
  return (bool) preg_match($regex, $phonenumber);
}