Regex for password must contain at least 8 characters, at least 1 number, letters and special characters

I need a regex that must have at least one numeric character, both upper and lower case allowed, special characters also allow this expression

/^.*(?=.{6,10})(?=.*\d)(?=.*[a-zA-Z]).*$

      

but it is not valid for max 10 characters.

+3


source to share


2 answers


It sounds like you want something like this,

^(?=.*\d)(?=.*?[a-zA-Z])(?=.*?[\W_]).{6,10}$

      



The above regex only allows 6-10 characters. And it also checks for at least one digit, upper or lower letter, and at least one special character (characters other than letters and numbers).

+2


source


The following regex will limit your length and allow special characters.



^(?=.*\d)(?=.*[a-zA-Z]).{6,10}$

      

+2


source







All Articles