Are Leading Zeros Required For Range Validation

The quick answer to this, NO. If you have a range validator that appears to want you to have leading zeros chances are you made a bone headed mistake. Much like I did just now. I forgot to set the Type property of my range validator which gave me some interesting results.

The below range validator required me to enter 01 – 100. Another odd thing about this mistake was that a value of 43, had to be 043.

<asp:RangeValidator ID="valrngTest" runat="server" ControlToValidate="txtTest" 
    Text="*" ErrorMessage="Test must be between 0 - 100." SetFocusOnError="true" 
    Display="Dynamic" MinimumValue="0" MaximumValue="100">
</asp:RangeValidator>

This one worked just as you would expect. Notice the addition of the Type=”Integer”.

<asp:RangeValidator ID="valrngTest" runat="server" ControlToValidate="txtTest" 
    Text="*" ErrorMessage="Test must be between 0 - 100." SetFocusOnError="true" 
    Display="Dynamic" MinimumValue="0" MaximumValue="100" Type="Integer">
</asp:RangeValidator>
Advertisements

About SheldonS

Web developer for over 15 years mainly with Microsoft technologies from classic ASP to .NET 4. Husband, father, and aspiring amateur photographer.

Posted on February 29, 2012, in .NET and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: