Validation of Phone Numbers

Hi,

Is there any way to validate for phone numbers (US) as well as international phone numbers in ColdFusion? Thanks
MameaAsked:
Who is Participating?
 
Russell2566Connect With a Mentor Commented:
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
      ^[2-9]\d{2}-\d{3}-\d{4}$

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
0
 
_agx_Commented:
If you need to handle international phone numbers as well, I would suggest reviewing the standards first.  
http://en.wikipedia.org/wiki/E.164
http://www.itu.int/net/home/index.aspx

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.
0
 
MameaAuthor Commented:
Hi,

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.

Thanks
0
 
_agx_Connect With a Mentor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.