简体   繁体   中英

asp.net Rangevalidator displaying error message even though value is within range

This is the code that I am using but when I run that code it display an error message even if I put value within range.please Can anyone help me with this?

<tr>
                <td class="auto-style4">Password</td>
                <td class="auto-style3">
                    <asp:TextBox ID="Pass" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="Pass" ErrorMessage="Please enter Password" ForeColor="Red"></asp:RequiredFieldValidator>
                    <br />
                    <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="Pass" Display="Dynamic" ErrorMessage="Password range (1 -10)" ForeColor="Red" MaximumValue="10" MinimumValue="1"></asp:RangeValidator>
                </td>
            </tr>

with this RangeValidator you are declaring that textbox value should be within 1 to 10 that means if you input 11 or 0 or any integer which is not between 1 to 10 it will show ErrorMessage . I think you want to check the textbox length between 1 to 10 then you need a RegularExpressionValidator like below

<asp:RegularExpressionValidator ID="RegExp1" runat="server"    
 ErrorMessage="Password range (1 -10)"
 ControlToValidate="Pass"    
 ValidationExpression="^[a-zA-Z0-9'@&#.\s]{1,10}$" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM