Welcome to WebmasterWorld Guest from 34.237.76.249

Forum Moderators: ocean10000

Message Too Old, No Replies

Zipcode Validator

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


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"/>
6:13 pm on Sept 28, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


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.
9:39 pm on Sept 28, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


So short of doing that there is no way around this?
4:53 am on Sept 29, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


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.
3:30 pm on Sept 29, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


Now that I did not know. Thanks