Monday, October 9, 2006

Phone Number Validation - The Next Level

If you are computer programmer or an aspiring computer programmer, more often than not, you will be required to write some kind of application or web page which requires a phone number. There are a number of code snippets on the web in the language of your choice on how to verify whether the number entered by your end user is actually in the correct format (for North American standards, it's nnn-nnn-nnnn, where n is a number). Some snippets are even clever enough to translate letters into numbers based on their placement on a phone pad.

While this method of phone number validation is good enough for most business cases, this method is not enough in other business cases. For example, what if you are writing a call center application or a web site which collects information for sales people to contact as a potential client/customer? If I entered 111-111-1111, it is in a valid format (North American standards), but it is NOT a valid phone number according to the North American standards. (Sales people get really annoyed when they get a lead for the lad himself, Mr. Hunt, at phone number 111-111-1111.) It's a good idea to familiarize yourself with the telephone number standards while writing your program.

If you are writing for one market in mind (ex: the US or Canada), it's relatively simple to do. In that case, you only need to familiarize yourself with North American standards. However, if you are writing for an international market, it can get tricky. For example, according to the North American phone standards, area and city codes cannot start with a 0, but according to the UK phone standards, area and city codes can start with a 0, which can be dialed within the UK.

Learning about the telephone plans will give you information about:

  • The valid format for an area code (a.k.a. the numbering plan code) and city code (a.k.a. the Central Office code).

  • Valid area codes

  • Reserved codes used only by the phone company

  • Valid codes for toll-free numbers



How you code the validation is up to do. Here are some ideas:

  • If you are using an object-oriented language, you can create a class that performs this action, since the validation code can vary depending on what standards you are using.

  • If you are not using an object-oriented language, create a routine that can be "included" or "referenced" in your program.

  • In North American, some companies offer a free file download of the valid area codes used in North America. You can download this file and store in a database table. Then, validate the area code against the table.



Would you like to read more? Here are links to the UK and the North American phone plans:

No comments: