[Last Call] Learn how to a build a cloud-first strategyRegister Now


Validation of Phone Numbers

Posted on 2007-10-02
Medium Priority
Last Modified: 2013-12-20

Is there any way to validate for phone numbers (US) as well as international phone numbers in ColdFusion? Thanks
Question by:Mamea
  • 2

Accepted Solution

Russell2566 earned 1000 total points
ID: 19999445
You could use the cfinput tag if you wanted. Personally I hate cfform/cfinput so I do all my own validation. Using javascript or server side code you could go as simple as stripping out the non-numbers and making sure it's the right length... or us regex, again in javascript or serverside...

Here is a regex example of validating a US number that I use from regex lib

This expression matches a hyphen separated US phone number, of the form ANN-NNN-NNNN, where A is between 2 and 9 and N is between 0 and 9.
Matches: 800-555-5555 ||| 333-444-5555 || |212-666-1234
Non-Matches: 000-000-0000 ||| 123-456-7890
LVL 52

Expert Comment

ID: 19999876
If you need to handle international phone numbers as well, I would suggest reviewing the standards first.  

Once you understand that its just a matter of structuring you db table to store the values properly and designing a regular expression to match.

Author Comment

ID: 20011548

Yes, I don't like to do cfform and I also do all of my own validation. I was wondering if there was a custom tag or some other method in CF to validate phone numbers.

LVL 52

Assisted Solution

_agx_ earned 1000 total points
ID: 20014226
Unfortunately I don't know of a custom tag that does international phone numbers as well as US phone numbers.  I would just figure out the pattern based on the itu standards and then create a regex to match it. Sorry I couldn't be of more help.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
Suggested Courses

830 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