javascript - regular expression for no more than 2 repeated letters/digits -
i have requirement need handle regex expression no more 2 same letter/digit in xsl file
-no space -does not support special chars. -support (a-z,a-z,0-9), -require 1 of a-z, -require 1 of 0-9, -no more 2 same letter/digits (i.e bbb fail, bb accepted)
what have far
(?:[^a-za-z0-9]{1,2})
this regex it: ^(?!.*([a-za-z0-9])\1{2})(?=.*[a-z])(?=.*\d)[a-za-z0-9]+$
here's breakdown:
(?!.*([a-za-z0-9])\1{2})
makes sure none of chars repeat more twice in row.
(?=.*[a-z])
requires @ least 1 lowercase letter
(?=.*\d)
requires @ least 1 digit
[a-za-z0-9]+
allows letters , digits
edit : removed extraneous .*
negative lookahead
Comments
Post a Comment