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

后端 未结 4 1719
醉酒成梦
醉酒成梦 2021-02-20 16:33

I want to validate password entered by user for following criteria :

Password should be at least 8 characters long and should contain one number,one character an

4条回答
  •  广开言路
    2021-02-20 17:20

    You can use this regex pattern it will work fine:

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

    But you need to write it in .ts file (controller class) because if you write regex in .html file as the 'type' of the input field is a 'password' you will always throw the error "Invalid password". Because you are writing a regex to check the alphanumeric and special character input but as the input field is of type password then this regex will check the encrypted input which will always fail the case.

提交回复
热议问题