Phone number validation rules

From Catglobe Wiki
Revision as of 09:51, 7 March 2011 by 127.0.0.1 (talk | contribs) (jrfconvert import)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



Phone number validation rules

In order to avoid getting many unclean phone numbers in the database, Catglobe supports an extensive phone number validation system, explained in the following help file.

A telephone number or phone number is a sequence of numbers used to call from one telephone line to another in a telephone network. When telephone numbers were invented, they were short - as few as two or three digits - and were used by people to call a few neighbors. As phone systems have grown and interconnected to encompass the world, telephone numbers have grown longer and more complex, and in addition to telephones they now designate many other devices, such as computers and fax machines.

Most telephone networks nowadays are interconnected in the international telephone network, where the format of telephone numbers is standardized by ITU-T in the recommendation E.164, which specifies that the entire number should be 15 digits or shorter, and begin with a country prefix. For most countries, this is followed by an area code or city code and the subscriber number, which might consist of the code for a particular telephone switch. ITU-T recommendation E.123 describes how to represent an international telephone number in writing or print, starting with a plus sign ("+") and the country code. When calling an international number from a fixed line phone, the + must be replaced with the international call prefix chosen by the country the call is being made from. Mobile phones generally allow the + to be entered directly.

How the system generates a phone number string to validate

In source file, we have 2 mapped columns named country_code and phone_number. System will use these values to generate a phone number string and check whether it is valid or not.

The algorithm to generate input string to validate is as follows:

Step 1: if source phone number value starts with “+”, system will validate and parse this value as if it includes country_code already.

  • If validation is successful, system will parse this phone number value to country, area code, number and extension.
  • If source country code value is not empty and is different than parsed country code, show warning message that “Warning: mapped country code is different than country code included in source phone number value”
  • If validation isn't successful, show error message.

Step 2: if source phone number value doesn't start with “+”.

  • If source country code value is not empty, system will validate and parse the string +[country_code][phone_number].
  • If source country code value is empty, system will validate and parse the string +[ DefaultCountryCodeForImportedUsers][phone_number]

=> If validation returns false, error will be occur. Error type: Error. “Message: Invalid phone number format.”

=> If validation returns true, system will parse input phone number string to country_id, area code, number and extension value to import to database.

How does phone number validation work?

A string considered as phone number will have format [country_number][area_code][number][extension]. [Area_code] and [Extension] could be null.

There are some rules to validate a phone number

- All its characters must be digits from 0-9.

- Phone number must begin with an optional '+' followed by 6 to 20 digits and then followed by an option '*' or '#' and some digits showing the phone extension.

There are two phone types: land line and mobile. A mobile number doesn't include area code and extension. Here are some examples

Ex 1: +31 0302587892 is land line

  • country_number is 31
  • area_code is 30
  • number is 2587892
  • extension is blank

Ex 2: +31 0302587892#12 is land line

  • country_number is 31
  • area_code is 30
  • number is 2587892
  • extension is 12

Ex 3: +45 98035875 is land line

  • country_number is 45
  • area_code is blank
  • number is 08035875
  • extension is blank

Ex 5: +45 53035875 is mobile

  • country_number is 45
  • number is 53035875

Besides, the format and allocation of local phone numbers are controlled by each nation's respective government

At this time, we just support in detail for some countries, they are : Netherlands , Belgium, France, Spain, Italy, Switzerland, UK, Denmark, Sweden, Norway, Germany, Australia, Vietnam, Ireland, Finland, Latvia, Ukraine. For the other countries, we will have a common validation which won't be exactly for this country.

There are two basic phone number type: mobile or land line. The difference here is that mobile doesn't have area code and extension while a land line could have. Each country has its own rules for mobile and land line number.

The description below shows in detail how the system validates a mobile or land line for each country.

<Will be inserted soon>