Currently, you have:
^[[:digit:]]{5}(( |-)?[[:digit:]]{4})?$
( |-) represents a space or hypen. If you just want a hypen, you don't
need the parens, space, or pipe.
( |-)? means that the space or hypen is optional.
So, if you want to force a hypen for 9-digit zipcodes, you would want
^[[:digit:]]{5}(-[[:digit:]]{4})?$
--Ben
Che Vilnonis wrote:
> Hello all. I use the following to regular _expression_ to validate zipcodes.
>
> <cfif NOT REFind('^[[:digit:]]{5}(( |-)?[[:digit:]]{4})?$', #FORM.BillZip#)>
> <cfset CreateAccountFlag = "Yes">
> <cfset BillZipInvalidFlag = "Yes">
> </cfif>
>
> When a customer inputs a 9 digit zip code WITHOUT the hyphen, no error is
> set. (i.e. 902101444)
> How would I modify this to incorporate a mandatory hyphen when a 9 digit zip
> code is inputed and still work for all other zip codes?
>
> TIA...Che
>
[Todays Threads]
[This Message]
[Subscription]
[Fast Unsubscribe]
[User Settings]
[Donations and Support]
- Quick Regular Expression Question. Che Vilnonis
- Re: Quick Regular Expression Question. Ben Doom
- Re: Quick Regular Expression Question. Jerry Johnson
- RE: Quick Regular Expression Question. Che Vilnonis
- Re: Quick Regular Expression Question. Marlon Moyer
- RE: Quick Regular Expression Question. Pascal Peters