You are here

function valid_jo_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 phone.jo.inc \valid_jo_phone_number()

Verification for Jordanian Phone Numbers.

Parameters

string $phonenumber:

Return value

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

File

include/phone.jo.inc, line 23
This plugin is contributed by Untitled Web http://untitledstudios.com @author Rashad Majali <rashad.612@gmail.com> http://drupal.org/user/319686

Code

function valid_jo_phone_number($phonenumber) {

  /**
    Accepts:
    Mobile numbers: (X refers to network code, it might be 7,8,9).
      +9627X1234567
        +962-7X1234567
        +962 7X1234567
        009627X1234567
        00962-7X1234567
        00962 7X1234567
      962... accepted as well
      07X1234567
    Local area numbers: (X refers to region code, i.e. Amman[6], north [2], middle [5], south[3]).
        +962X1234567
        +962-X-1234567
        +962X-1234567
        +962 X 1234567
        +962X 1234567
        +962 X1234567
      00962X1234567
        00962-X-1234567
        00962X-1234567
        00962 X 1234567
        00962X 1234567
        00962 X1234567
      962... accepted as well
      0X1234567
        0X-1234567
        0X 1234567
  Rejects:
    Generally rejects any number without leading code.
      starts with X instead of 0X
    Mobile:
        7X1234567
        7 X1234567 and similar formats
        +962 7 X1234567 and similar formats
    Local:
        X1234567
        X-1234567
        X 1234567 and similar formats
  */
  $regex = "/(^(\\+962|00962|962|0)[-\\s]{0,1}[7]{1}[7-9]{1}[0-9]{7}\$) | (^(\\+962|00962|962|0)[-\\s]{0,1}[2-6][-\\s]{0,1}[0-9]{7}\$)/x";
  return (bool) preg_match($regex, $phonenumber);
}