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]

Reply via email to