Forum Moderators: open

Message Too Old, No Replies

Zipcode Validator

         

andrewsmd

6:04 pm on Sep 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a zipcode regex validator that works fine as long as the user puts in something. However, if the textbox is blank completely then it doesn't work. Any ideas why? Here is my code. Thanks
<asp:RegularExpressionValidator ID="reZipCode" ControlToValidate="zipInput"
ValidationExpression="^(\d{5}$¦^\d{5}-\d{4}$){1}"
ErrorMessage="Not a valid Zip code!"
Display="static" runat="server" CssClass="errorMessage"/>

marcel

6:13 pm on Sep 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I usually place a requiredFieldValidator as well as a regularExpressionValidator in this type of situation as I always seem to have this problem as well.

Maybe someone more versed in Regular expressions can help here.

andrewsmd

6:23 pm on Sep 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is how I have been going around it, but I know there has to be a way to do this in the regex. Placing two of them takes up too much space in my table.

Ocean10000

9:39 pm on Sep 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The Regex code will not be called if the text box is blank. Its a feature of the default validator controls except the required validator control.

I wrote my own validator controls way back when 1.0 came out because of this and other things.

andrewsmd

9:56 pm on Sep 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So short of doing that there is no way around this?

marcel

4:53 am on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Placing two of them takes up too much space in my table.

By setting the Display Property of the control to Dynamic it will no longer take up any space when hidden.

andrewsmd

3:30 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now that I did not know. Thanks