Reputation: 1369
I need a regex to validate a password input by the user through JS in an online registration form. The criteria for the password is the following:
I have tried to use the following regex, however if you input any special character such as '?' before the curly bracket {, it would allow it as a valid input. I am new to using regex and not really familiar so might be there's something minor in it:
^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[,#?!=@%&\^\$\*\)\(\_\.\'\"\+\-]).{8,}$
Can someone help me with a regex for this or point any issues in mine? Thanks
Upvotes: 1
Views: 426
Reputation: 29441
To easily forbid characters, change .{8,}
to [^{}]{8,}
:
^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*[,#?!=@%&\^\$\*\)\(\_\.\'\"\+\-])[^{}]{8,}$
Or include any authorized char within the class:
[a-zA-Z\d,#?!=@%&\^\$\*\)\(\_\.\'\"\+\-]{8,}
Upvotes: 3