-2

I want the regex for password textbox with below criteria

  • (a) At least One character

  • (b) At least One special character

  • (c) At least One numeric value

  • (d) and the length should be greater than 8 digit

chiwangc
  • 3,566
  • 16
  • 26
  • 32
Nad
  • 4,605
  • 11
  • 71
  • 160
  • 1
    Have you looked at [this answer](http://stackoverflow.com/questions/3466850/complex-password-regular-expression)? – James Newton May 24 '15 at 14:41

1 Answers1

0

Tried something like below and it worked.

Solution 1:-

 function checkPassword(password) {
        var pattern = /^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/;
        if (!pattern.test(password)) {
            $(".password_error").show();
        } else {
            $(".password_error").hide();
        }
    }

Solution 2:-

<asp:TextBox ID="txtPolicy4" runat="server"></asp:TextBox><br />
    <asp:RegularExpressionValidator ID="Regex4" runat="server" ControlToValidate="txtPolicy4"
        ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}"
    ErrorMessage="Password must contain: Minimum 8 characters atleast 1 UpperCase Alphabet, 1 LowerCase Alphabet, 1 Number and 1 Special Character" ForeColor="Red" />

Both the solution worked for me, but I preferred the second solution.

Nad
  • 4,605
  • 11
  • 71
  • 160