开发者

Regex work in chrome and explorer but not in firefox

I am using Jquery to validate my textbox. my particular regex condition 开发者_如何学编程is...

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

Issue is it work great and efficiently in Chrome and explorer but firefox gives error for this regex. I checked using firebug. Even it also not work for firefox.

Error: invalid range in character class


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

[A-Za-z.\s-]

Alternatively you can escape it:

[A-Za-z.\-\s]


Escape the hyphen:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜