admin管理员组文章数量:1426907
I got Invalid range in character class issue when trying to use regex
/^[a-zA-Zа-яА-ЯЁё0-9_-\s]{6,20}$/
But the issue is only in Firefox, in Chrome it's ok.
With this regex I am trying to say "only latin, russian letters, numbers, space and '_' and '-' signs allowed"
I got Invalid range in character class issue when trying to use regex
/^[a-zA-Zа-яА-ЯЁё0-9_-\s]{6,20}$/
But the issue is only in Firefox, in Chrome it's ok.
With this regex I am trying to say "only latin, russian letters, numbers, space and '_' and '-' signs allowed"
Share Improve this question asked May 6, 2014 at 14:04 Lambrusco.NewbieLambrusco.Newbie 1692 silver badges13 bronze badges 3-
2
Try to put the
-
at the end or at the begining of the class or escape it. – Casimir et Hippolyte Commented May 6, 2014 at 14:05 - possible duplicate of Accept international name characters in RegEx – Cerbrus Commented May 6, 2014 at 14:05
- Thanks Casimir that was the issue! – Lambrusco.Newbie Commented May 6, 2014 at 14:07
1 Answer
Reset to default 6The _-\s
is creating a range between the underscore and space characters. You need to either escape the -
as in _\-\s
or put it at the end:
[a-zA-Zа-яА-ЯЁё0-9_\s-]
Also beware of the а-я
range. If this is the same as the Latin 1 a
the range may not be what you expect at all.
本文标签: javascriptInvalid range in character class Regex FirefoxStack Overflow
版权声明:本文标题:javascript - Invalid range in character class Regex Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745486349a2660400.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论