Why is this regex allowing a caret? -
^(?=.*[0-9])(?=.*[a-z])[0-9a-z-]{17}$ should match "17 alphanumeric chars, hyphens allowed too, must include @ least 1 letter , @ least 1 number"
it'll correctly match:
abcdf31u100027743 and correctly decline match:
ab$df31u100027743 (and other non-alphanumeric char)
but apparently allow:
ab^df31u100027743
because character class [a-z] matches symbol.
[a-z] matches [, \, ], ^, _, ` , english letters.
actually, common mistake. should use [a-za-z] instead allow english letters.
here visualization expresso, showing range [a-z] covers:
![screenshot expresso showing ascii table, can see [a-z] range covers](https://i.stack.imgur.com/qxdlz.png)
so, this regex (with i option) won't capture string.
^(?=.*[0-9])(?=.*[a-z])[0-9a-z-]{17}$ in opinion, safer use ignorecase option avoid such issue , shorten regex.
Comments
Post a Comment