javascript - Regular expression for y,yes, Y, YES ,1 -
i need write regex validating string. regular expression should pass string if contains of following: y
, y
, yes
, yes
, 1
. letters can in case. new regular expression , javascript.
you need add optional group case-insensitive i
modifier.
/y(?:es)?|1/i.test(str)
or
/[1y](?:es)?/i.test(str)
or
/[y1]/i.test(str)
for doing exact match.
/^(?:y(?:es)?|1)$/i.test(str)
Comments
Post a Comment