PHP Phone Validation Class
A few days ago, I wrote a post about validating NANPA regulated phone numbers. So late last night, I figured since I have already done the research and figured out the work, why not build a class and put it online for everyone? So that’s what I did.
During the process, I realized how easy it would be to apply the “optional” filters I discussed in my previous post. I document them on the Google Code wiki where my open source repository is.
So if you need a great PHP Class for validating NANPA specific phone numbers, please feel free to get the source from my repository on Google Code. You can see the description and documentation on the wiki at the same site.
In a nutshell, the php class will cleanse the phone number (accounting for the possibility of an extension), validate, and format. It also has the options of filtering on 900 numbers, toll free numbers, special services numbers, etc. I have released it under the Creative Commons license. So if you feel like you would like to contribute. Please feel free to send me suggestions. You can post them here or submit an issue at Google Code.
Stay tuned, I will be updating the code periodically. For example, future road map enhancements are planned to include additional filters such as:
- unused/unassigned area codes
- area code by country
- area code by state
- nxx by area code
I also plan on developing a verification method. While the only way to prove the number belongs to the individual listed it should be called, there are other verification methods that can be accomplished digitally with weighted results. This means that we can check the phone number to a known source (i.e. white pages). For example, we can tally a score for certain tests on the digital verification process. For example, when we look up the number, does:
- the number exist (counts as 1 point)
- does the last name match (counts as 2 points)
- does the full name match (counts as 3 points)
This will tell us with a weighted score, how certain we are that the number is verified from a third party without having to actually call. In addition, if we test multiple sources, the score will increase for each source. This will improve the chances that the phone number is in fact verified.
In addition to the coding updates, I will also be converting this class to be used with my favorite php framework, CakePHP. It will be added to the repository as well. While it is simple for anyone who knows CakePHP to convert it, I would like to have a “drag-n-drop” CakePHP class that I can use without having to convert it every time or track it somewhere else.
I would be interested in your feedback. Please feel free to comment. And as usual, if you would like to support my coding habit (which is better than drugs or alcohol I might add), you can always donate using the donate link on the side bar.
Happy coding!
2 Comments
Chuck Burgess on June 4th, 2010
Glad you like it!















>
rgrissinger on June 4th, 2010
Hey buddy, thanks for the help. Also, love the title and tagline of your blog. It made me chuckle (hee hee).