0

The password field should be more than 8 characters and include at least one special characters. How to meet the 'at least one special character' requirement in AngularJS?

<input type="password" name="pwd" data-ng-minlength="8" data-ng-model="user.pwd" />

How to add password validation using regular expression in angularjs according to certain criterion?

This question is very helpful to me, but my password requirement is slightly difference, like no number is allowed in my password, and I want to seperate the length requirement and special character requirement if possible so I can tell users what is the exact error. And I just wonder where can I learn how to set up ng-pattern? For me, they look like random characters...like this one:

ng-pattern="/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$/"
Community
  • 1
  • 1
Joey Zhang
  • 363
  • 6
  • 18
  • 4
    Possible duplicate of [How to add password validation using regular expression in angularjs according to certain criterion?](http://stackoverflow.com/questions/36352562/how-to-add-password-validation-using-regular-expression-in-angularjs-according-t) – Thilo May 26 '16 at 01:43
  • You will need to make your own directive. [Angular Custom Validation](https://docs.angularjs.org/guide/forms#custom-validation) – Clint May 26 '16 at 01:47
  • 1
    That *random character* pattern is a [regular expression](http://www.regular-expressions.info). – Ken White May 26 '16 at 02:08

1 Answers1

0

You can do this easily with below code

var regularExpression = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,16}$/;

With the above regex you can complete your task, for detail study of it go to the link :

https://www.w3schools.com/Jsref/jsref_obj_regexp.asp

Soni Kumari
  • 126
  • 1
  • 5