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>
Posted on February 29, 2012, in .NET and tagged Validation. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0