Categories
Misc

Password Validation With All Special Characters

A quick post on how to build a regex for password validation with all special characters.

Criteria for Password Validation

The enforced password requirements are as follows:

  • Must be at least 8 characters in length
  • Must contain at least 1 character
  • Must contain at least 1 digit
  • Must contain at least 1 special character

Most importantly, all the special characters specified here should be handled by the regex.

Regex For Password Validation

Here’s the final regex string which meets all of the mentioned criteria.

^(?=.*?[a-zA-Z])(?=.*?[0-9])(?=.*?[!@#\][:()"`;+\-'|_?,.</\\>=$%}{^&*~]).{8,}$