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

preview_player
Показать описание
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,}$
Рекомендации по теме
Комментарии
Автор

Thank you so much, your solution is very elegant

GAks-hcxk