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
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.