Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid range in character class Regex Firefox

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"

like image 452
Lambrusco.Newbie Avatar asked Oct 16 '25 19:10

Lambrusco.Newbie


1 Answers

The _-\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.

like image 200
Explosion Pills Avatar answered Oct 18 '25 07:10

Explosion Pills



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!