How to force user to type more than any number of characters in password field
I want to force user to type more than 6 characters in password field.we cannot usee range validator because password c开发者_Python百科haracters can be mix(i.e.Numeric or alphabates or special characters)
You can use a RegularExpressionValidator
if you're using validators for other things, might as well stay with that:
<asp:RegularExpressionValidator ID="valMinLength" runat="server"
ControlToValidate="myPasswordBox"
ErrorMessage="Password should have at least 6 characters"
ValidationExpression="/{6,}/" />
You can use a RegEx validator that it must match the pattern
[^\s]{6,}
Try using CustomValidator
<script runat="server">
bool CheckPasswordLen()
{
if (textbox1.Text.Length < 6)
return false;
else
return true;
}
</script>
<asp:textbox id="textbox1" runat="server">
<asp:CustomValidator id="valCustom" runat="server"
ControlToValidate="textbox1"
OnServerValidate="CheckPasswordLen"
ErrorMessage="*Password must be greater than 6 characters"*
</asp:CustomValidator>
精彩评论