I am trying to validate a string of the pattern IN-XXXXXXXX-X
, where X
is an alphumeric value. For It I need to write the regex expression
The regex I write is
/^IN-\w{8}-\w/g
But it validates alphanumeric as well as underscores in place of X.The other way would be
/^IN-[A-Za-z0-9]{8}-[A-Za-z0-9]/g
However this seems way to long. Is there a shorthand to write [A-Za-z0-9]
in order to validate alphanumeric
values.
[:alnum:]
for example^IN-[[:alnum:]]{8}-[[:alnum:]]
or^IN-(?i)[a-z0-9]{8}-[a-z0-9]