Validation of Phone Numbers

Posted on 2007-10-02
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
    LVL 4

    Accepted Solution

    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 51

    Expert Comment

    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


    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 51

    Assisted Solution

    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

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
    The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and Log…
    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: : Go t…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now