I have a regular expression testing for numbers(0-9
) and/or forward slashes (/
). It looks like this:
/^[0-9/]+$/i.test(value)
The standard clearly says you can put anything unescaped in a character class except \
, ]
and newline:
RegularExpressionClassChar ::
RegularExpressionNonTerminator but not ] or \
RegularExpressionBackslashSequence
RegularExpressionNonTerminator ::
SourceCharacter but not LineTerminator
( http://es5.github.com/#x7.8.5 ). No need to escape /
.
On the other side, I personally would escape everything when in doubt, just to make less smart parsers happy.