Regex to allow exactly one special character and Restrict few special characters in password

Regex to allow exactly one special character and Restrict few special characters in password

Professional Expertise

55 лет назад

5,221 Просмотров

Regex to allow exactly one special character in password. Also have regex to restrict some other special characters in password.

Below Regex will allow only one special character out of given set [!@#$%_].
^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=[^!@#$%_]*[!@#$%_][^!@#$%_]*$)[a-zA-Z0-9!@#$%_]{8,}$

If want to restrict few special characters then, below Regex can be used where currently [+-] is restricted.
^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?!.*[+-])(?=[^!@#$%_]*[!@#$%_][^!@#$%_]*$)[a-zA-Z0-9!@#$%_]{8,}$

Тэги:

#Password_Regex #Allow_only_one_special_characters_in_Password #Restrict_special_characters_in_Password #Special_characters_in_password
Ссылки и html тэги не поддерживаются


Комментарии: