Regex doesn't recognize underscore as special character -
/(?=^.{8,}$)(?=.*[_!@#$%^&*-])(?=.*\d)(?=.*\w+)(?![.\n])(?=.*[a-z])(?=.*[a-z]).*$/ i'm trying make regex password validation such password must @ least 8 chars , include 1 uppercase, 1 lowercase, 1 number, , 1 special char. works fine except won't recognize underscore (_) special character. i.e., pa$$w0rd matches, pass_w0rd doesn't. thoughts?
this portion of regex seems looking special characters:
(?=.*[!@#$%^&*-]) note character class not include underscore, try changing following:
(?=.*[_!@#$%^&*-]) you need modify or remove portion of regex:
(?=.*\w+) \w equivalent [^a-za-z0-9_], if underscore special character portion of regex cause fail. instead, change following (or remove it, redundant since check special characters earlier):
(?=.*[^\w_]) complete regex:
/(?=^.{8,}$)(?=.*[_!@#$%^&*-])(?=.*\d)(?=.*[^\w_])(?![.\n])(?=.*[a-z])(?=.*[a-z]).*$/
Comments
Post a Comment