You are here

function valid_za_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 phone.za.inc \valid_za_phone_number()

Verifies that $phonenumber is a valid South African phone number

Parameters

string $phonenumber:

Return value

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

File

include/phone.za.inc, line 21
CCK Field for South African phone numbers.

Code

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

  // define regular expression
  $regex = '/^((?:\\+27|27)|0)[ ]*((\\d{2})(-| )?(\\d{3})(-| )?(\\d{4})|(\\d{2})( |-)(\\d{7}))$/';

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