Regex works in chrome and explorer, but not in firefox

I am using jquery to validate my text box. my special condition for regular expression ...

/^[A-Za-z.-\s]*$/.. that is alphabets, space, hyphen, and dots. 

The problem is that it works fine and efficiently in Chrome and Explorer, but firefox gives an error for this regular expression. I checked using firebug. Even it also does not work for firefox.

 Error: invalid range in character class 
+4
source share
2 answers

To avoid a hyphen that has special meaning (a range of characters), you should put it at the end of the character class:

  [A-Za-z. \ S-]

Alternatively, you can avoid this:

  [A-Za-z. \ - \ s]
+8
source

Reset the hyphen:

/^[A-Za-z.\-\s]*$/

+1
source

All Articles