0

Markup

<form ng-submit="doRegister(registerForm);" novalidate name="registerForm">
    <input type="password" name="Password" ng-model="register.Password" 
        ng-pattern="/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/"/>
    <span ng-show="registerForm.Password.$error.pattern" class="help-block">
        min 1 lower char, 1 upper char, 1 digit and one special char 
    </span>
    
    <button type="submit" ng-disabled="registerForm.$invalid" >
        Submit
    </button>
</form>

I am testing the Password Strength with min 1 lower char and 1 upper char and 1 digit and one special char

I am testing this string: a1A@s.com //Failed

I am testing this string: 12345aA! //Passed

Am I doing anything wrong?

Community
  • 1
  • 1
Pankaj
  • 9,749
  • 32
  • 139
  • 283

1 Answers1

2

It is failing because @ is not part of your character class in last lookahead. You can also simplify your regex to this:

/^(?=.*[a-z])(?=.*[a-z])(?=.*[0-9])(?=.*[@!$#%]).{3,}$/

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643