Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reg exp formatting phone numbers

Status
Not open for further replies.

johk02

Programmer
Aug 20, 2003
169
AU
Hi,
I am trying to write a reg exp to verify that the phone number is entered correctly. I want the phone number to be entered like 99-9999 9999 and the reg exp I have is [0-9]{4}-[0-9]{4}(\s)[0-9]{4}. The problem is that it allows me to enter more than 4 numbers in the last block of numbers like 99-9999 999999999. Another question I have is how do you write an or statement with reg exp?? For example the number combination could be either 99-9999 9999 or 9999-999 999.

Thanks
Jonas
 
not really, you can do field validations using CFINPUT and regex direct in CF and while somewhat related to the regex in JS, has a few of it's own rules.

the regex validation can be done in the form itself or server side on submission (recommended actually to do both)

 
Thank you falconseye. I am actually going to use the exp on my validation page (as well as in the cfinput). I guess that qualifies it to be an coldfusion question :)

Thanks

Jonas
 
Might it be wiser to strip out any non integers and then count the remianing integers to make sure it is a valid number? I have filled out phone number forms where they validated it down to the () and - and god is it annoying.



Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
At the moment I count the numbers to verify that they are entering in at least 10 numbers. Some are entering the phone number 99-99999999 or 99-9999 9999.When they are outputted later on we have an inconsistency how the phone numbers are displayed. I just want to ensure that when they are outputted that they all look the same.

Jonas
 
so you need to format the numbers to look consistant, rather than force the user to type the number how you want? that would be much nicer I think.

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
if you just want consistency, you could also try using the mask attribute
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top