[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Validating phone and zip beyond a regular expression

Posted on 2007-08-03
9
Medium Priority
?
1,222 Views
Last Modified: 2012-08-13
I need a more bullet proof solution to validating phone numbers and postal codes (United States) I'm already using regular expressions that check for the right number of characters, no 555 numbers, no area codes starting with 0 or 1, and no area codes with 9 as a second digit. Zip codes I'm just doing a basic check for a 12345 or 12345-1234 zip code.

This isn't enough.

I was wondering if there is any public database I can connect to for validating phone numbers, zip codes, and states against each other to ensure that they are valid.
0
Comment
Question by:iambagels
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Assisted Solution

by:Scott Bennett
Scott Bennett earned 400 total points
ID: 19629053
you can get a database that matches the zipcode to the city, state for $5 here:
http://teamredline.com/zc/default.asp

you will have an issue with trying to validate the areacodes to a zip code because many many people these days are using cell phone numbers that have zip codes where they used to live but have moved and kept the same number, or people who use VOIP services like vonage can have whatever area code they want. It would be a real customer service headace if you start restricting people based on the fact that their area code does not match their zip code or ,city, or even state.
0
 
LVL 10

Accepted Solution

by:
stormist earned 1400 total points
ID: 19630357
If this is really important, you can interface with a phone validation service that requires the user to for instance press "Call now" then enter a verification code:
http://www.phoneconfirm.com/
0
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 19630370
Hi,

please specify this in regular expression

\[2-9]{1}\[0-8]{1}\[0-9]*

With Regards,
DIvyesh Doshi
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:LeeKowalkowski
ID: 19636937
iambagels> This isn't enough.

Why not?  What do you want the rules to be?

iambagels> I was wondering if there is any public database I can connect to for validating phone numbers, zip codes, and states against each other to ensure that they are valid.

Valid meaning that they exist too?  What if they have a newly issued zip code or telephone number?  What kind of business model do you have that would only accept business from a potentially stale validation cache?  And a public database is likely to always be stale.

What is your business reason which makes it so critical for the user to enter an existing telephone number?  I'm just curious as to whether a proper cost/benefit analysis had been done, that's all.  Many businesses tend to not care so much for invalid telephone numbers, and post codes lookups are commonly available (although in the UK, one would only really consider subscribing to the Royal Mail's PAF service).

I don't know about the US, but in the UK, you can SMS any telephone (if it's a non-SMS telephone they get a phone call from an automated Tom Baker http://news.bbc.co.uk/1/hi/entertainment/4665254.stm).  So you could send an activation code to the user's entered telephone number for them to use on your site.  I think this sounds very similar to stormists's suggestion, but may be cheaper.

--
Lee
0
 
LVL 14

Expert Comment

by:Scott Bennett
ID: 19639778
As I said before validating the phone number area code to the city,state,zip in the address is a bad idea. I do agree with stormists idea that If you absolutely need to make sure their phone number is valid you should use a phone number validation service such as phoneconfirm.com. This is how many SSL Certificate authorities work when you purchase an ssl certificate.
0
 
LVL 2

Author Comment

by:iambagels
ID: 19642419
the reason i'm asking is because the company i work for does cost per lead (CPL) advertising. recently there have been problems with clients not accepting leads because the phone number was invalid. (they wont pay for invalid leads) i dont deal with the clients so i dont know exactly what this means. It could be a wrong number, It could be a n invalid number, i dont know for sure.

divyeshhdoshi: currently i'm using these three regex's to validate (this is ASP, i'm doing JavaScript checks too):
            if ( Len(home_phone) = 0 ) then
                  form_errors(err_num) = "'Home Phone' is invalid"
                  err_num = err_num + 1
            elseif ( ereg(home_phone,"^[2-9][0-8][0-9][- .]?[0-9]{3}[-. ]?[0-9]{4}$",true) = false ) then
            ' if the phone number does not meet the following rules:
            ' - must be 10 digits
            ' - area code cannot start with 0 or 1
            ' - 9 cannot be the second number of an area code
            ' - separators may be "-", " ", or "." and are optional
            ' - if separators are used, numbers must be grouped ### ### ####
                  form_errors(err_num) = "'Home Phone' is invalid"
                  err_num = err_num + 1
            elseif ( ereg(home_phone,"^[2-9][0-8][0-9][- .]?555[-. ]?[0-9]{4}$",true) = true ) then
            '' if the 4th, 5th and 6th digits are all "5" (### 555 ####)
                  form_errors(err_num) = "'Home Phone' is invalid"
                  err_num = err_num + 1
            elseif ( ereg(home_phone,"^[2-9]11[- .]?[0-9]{3}[-. ]?[0-9]{4}$",true) = true ) then
            '' if area code is #11
                  form_errors(err_num) = "'Home Phone' is invalid"
                  err_num = err_num + 1
            end if
0
 
LVL 14

Expert Comment

by:Scott Bennett
ID: 19643138
you can validate it all you want, you can even match the area code to the zip, you can still be fake/wrong numbered. The only way to ensure the phone number is really the phone number of the person that is filling out the form is to have your system validate it, by calling the number while the person is filling out the form on your site, then have them enter a number/passphrase/code that is displayed on the site and confirm this is their phone number. this is the kind of service that comanies like phoneconfirm.com provide.
0
 
LVL 16

Assisted Solution

by:LeeKowalkowski
LeeKowalkowski earned 200 total points
ID: 19644513
I don't see why you don't just take the hit.  I'm sure it's cheaper to send the odd invalid lead than to invest all that effort trying to prevent them in the first place.  Most businesses operate a returns policy of some sort, they don't expect absolutely every instance of a product they sell to be in perfect working order.

Providing they return the leads they want refunds for so you can verify they are actually invalid if you need to.

--
Lee
0
 
LVL 2

Author Comment

by:iambagels
ID: 19655278
Thanks for the help guys. It looks like my company is looking into something like PhoneConfirm. Personally I've been saying what Lee posted. I don't think it's worth it.

Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question