How to force the user to enter more than any number of characters in the password field

I want to force the user to enter more than 6 characters in the password field. We cannot use a range validator because password characters can be mixed (e.g. number or alphabet or special characters)

+3
source share
3 answers

You can use RegularExpressionValidatorit if you use validators for other things, you can also stay with this:

<asp:RegularExpressionValidator ID="valMinLength" runat="server"
 ControlToValidate="myPasswordBox"
 ErrorMessage="Password should have at least 6 characters"
 ValidationExpression="/{6,}/" />
+3
source

You can use the RegEx validator to match the pattern.

[^\s]{6,}
+2
source

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>
0

Source: https://habr.com/ru/post/1736486/


All Articles