regex - Javascript regular expression -


i making form , there 1 more thing cant figure out :(

i need regular expression password must @ least 7 characters long. there can small , big letters , must contain @ least 1 number.

i tried

[0-9]+[a-za-z]){7}$   

you can use lookahead:

^(?=.*\d)[a-za-z\d]{7,}$ 

(?=.*\d) lookahead checks digit in string. basically, .* matches whole string , backtracks 1 1 match digit. if matches digit, regex engine comes position before match. so, checks pattern.

{7,} quantifier matches previous pattern 7 many times

^ beginning of string


Comments