Monday, March 28, 2016

Validate strong password using RegularExpressionValidator

In this article I am going to explain how to validate a user for entering strong password.

Validation Expression

ValidationExpression="^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,16}$"

Note
  • Must have at least a minimum of (8 characters) and not more than a maximum of (16 characters) as the length.
  •  Must have 1 numeric digits.
  • Must have 1 alphabet and 1 Special characters like {! @ # $ % ^ & *}
Code

<asp:TextBox ID="txtpassword" TextMode="Password" runat="server" ></asp:TextBox>
    <span style="color: #ff0033; width: auto;">*</span>
<asp:RequiredFieldValidator ID="rfvtxtpassword" ValidationGroup="S"  ControlToValidate="txtpassword" runat="server" ErrorMessage="Please Enter User Name"></asp:RequiredFieldValidator>
   <asp:RegularExpressionValidator ID="Regtxtpassword" runat="server" ValidationGroup="S"
                                Display="None" ErrorMessage="Password Message" ControlToValidate="txtpassword"
                                ValidationExpression="^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,16}$"></asp:RegularExpressionValidator>


for RegularExpressionValidator download ajaxtoolkit

No comments:

Post a Comment