dotcoder
dotcoder

Reputation: 2931

how to check whether a phone number actually exists in US

We have a database of contacts and their phone numbers, and we would like to validate whether these phone numbers actually exists. I googled and did not find any solution. I am looking for one of the following, though I prefer the first option.

  1. Write code using existing phone library to check whether the phone of the contact actually exists. Probably we make the phone ring once or twice

  2. Use an existing software that can be used to ring the phone and validate user contact number manually.

Any help is greatly appreciated.

Upvotes: 3

Views: 4792

Answers (4)

Athena
Athena

Reputation: 3228

I've been working on an application that sends text messages to phone numbers. What I found is that text messages are actually handled from STMP. When you send a text message, it's being sent to

[email protected]

For example

[email protected] would refer to Verizon's number.

Hypothetically, then, you can check if a number exists by querying every service provider and checking for a response. Not sure if this will work with landlines.

You can find a list of service providers here

I would iterate through each of the providers on the list and check if you can extract a response. If you can't, time to change gears- a phone directory will contain landline numbers. We've eliminated every number on the American grid except any cell phone without texting, which is becoming increasingly rare.

Update: This technique is effective, but it can be illegal in some states if abused, and you may incur messaging charges. This should only be used to check a few select numbers, rather than attempting to profile users who haven't given consent for their info to be used.

Upvotes: 6

Maybe you could use Asterisk and use a connector to MySQL.

This is not really an answer but just an idea.

Maybe you can ask the community on their forum

Upvotes: 1

Fahad Idrees
Fahad Idrees

Reputation: 188

you can check

//10-digit phone number ^(?:+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$

//10-digit phone number, extension allowed ^(?:+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x.?|ext.?|extension)\s*(\d+))?$

//7 or 10-digit phone number ^(?:(?:+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$

//7 or 10-digit phone number, extension allowed ^(?:(?:+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x.?|ext.?|extension)\s*(\d+))?$

//10-digit phone number, vanity (alphanumeric) allowed ^(?:+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9a-z]1[02-9a-z]|[2-9a-z][02-9a-z]1|[2-9a-z][02-9a-z]{2})([0-9a-z]{4})$

//10-digit phone number, vanity allowed, extra characters allowed at end ^(?:+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9a-z]1[02-9a-z]|[2-9a-z][02-9a-z]1|[2-9a-z][02-9a-z]{2})([0-9a-z]{4})([0-9a-z]*)$

also, i have found the regex that check the USA numbers.

^([0-9]{3})[0-9]{3}-[0-9]{4}$ and

^[0-9]{3}-[0-9]{3}-[0-9]{4}$ is to use alternation ((...|...)): specify them as two mostly-separate options:

^(([0-9]{3})|[0-9]{3}-)[0-9]{3}-[0-9]{4}$ By the way, when Americans put the area code in parentheses, we actually put a space after that; for example, I'd write (123) 123-1234, not (123)123-1234. So you might want to write:

^(([0-9]{3}) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$

i hope it will work for all formats listed in wiki

http://en.wikipedia.org/wiki/Category:Telephone_numbers_in_the_United_States

you can also check http://regexlib.com/(A(3k11t-l-bx51TbStx_502eQq_kMPKrbAUku29jOowfM7aos6m8LTywGmKyLQ9PvcrjtaYPs4AczP5NXz2h7ZVMCGJSGrq8WHjaHgNAZ4GUc1))/DisplayPatterns.aspx?cattabindex=6&categoryId=7&AspxAutoDetectCookieSupport=1

Upvotes: 1

Quicker
Quicker

Reputation: 1246

Your question involves a lot of blurring about your requirements. However let's get some general ideas.

Any repository on natural facts ages instantly as long as there is no proper update process installed. This is a sort of fundamental truth and you can derive some conclusions from there if you keep in mind that there is no intrinsic process that keeps people from updating their number as they change:

a. any repository including these of existing software will have outdated data b. the second you are done with your phone number validation these data will age

You can derive following conclusions out of these conclusions depending on your requirements:

  1. If you aim for selling that database
    • you either need a very quick and/or parallel validation process which you can apply to all numbers short before seeling OR
    • you need an ongoing validation process, if you aim for on going sells -> I do not see a pragmatical way to implement that without being a global player (eg. like amazon or ebay)
  2. If you aim for using the database for yourself only the validation time should be as close as possible take part at your time of usage. The optimum is, that your validation and usage time is the same. But do not forget the update - so whenever somebody faults into a 'blind' number they must notify your database.
  3. The third party phone number repository might be of the same quality as yours which should raise the question if it worth the money

For randomly generating US phone numbers I would start from there:

http://en.wikipedia.org/wiki/North_American_Numbering_Plan

Upvotes: 2

Related Questions