You are here

function gb_validate_number in Phone Number 7

Same name and namespace in other branches
  1. 6 includes/phone.gb.inc \gb_validate_number()

Validate country level phone number.

Parameters

$number: Digits only value.

$ext: Digits only value.

$error: The error message to shown to user. Available parameters to use in the error message are

  • "%countrycode": the alpha-2 CC
  • "%phone_input": the original number input by user (could be invalid)
  • "%max_length": allowed maximum length of the phone number

Return value

boolean TRUE if it is a valid phone number for that country, FALSE otherwise.

File

includes/phone.gb.inc, line 37
CCK Field for United Kingdom phone numbers.

Code

function gb_validate_number($number, $ext = '', &$error) {

  // We don't want to worry about separators
  $number = cck_phone_clean_number($number);
  if (preg_match(_uk_phone_rules(), $number)) {
    return TRUE;
  }

  // t() is not needed
  $error = '"%phone_input" is not a valid United Kingdom phone number, it should be a 10 digit number like "99 9999 9999", with optional leading "0"';
  return FALSE;
}