javascript - Regex for alphanumeric with at least 1 number and 1 character -


i have regex

/^([a-za-z0-9]+)$/

this allows alphanumerics if insert number(s) or character(s) accepts it. want work field should accept alphanumeric values value must contain @ least both 1 character , 1 number.

why not first apply whole test, , add individual tests characters , numbers? anyway, if want in 1 regexp, use positive lookahead:

/^(?=.*[0-9])(?=.*[a-za-z])([a-za-z0-9]+)$/ 

Comments