最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why isn't this a valid regular expression? - Stack Overflow

programmeradmin1浏览0评论

This was just working a day ago but now throwing exception. I've pasted regex into online verifier and it looks good?

What am I missing?

<input type="text" class="form-control" name="nickname" id="nickname" value="Alicia"
       pattern="[\w\s\-\(\)\!\,\.]{3,45}">

Pattern attribute value [\w\s\-\(\)\!\,\.]{3,45} is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /[\w\s\-\(\)\!\,\.]{3,45}/: Invalid escape

Thanks for the help!

Casey

This was just working a day ago but now throwing exception. I've pasted regex into online verifier and it looks good?

What am I missing?

<input type="text" class="form-control" name="nickname" id="nickname" value="Alicia"
       pattern="[\w\s\-\(\)\!\,\.]{3,45}">

Pattern attribute value [\w\s\-\(\)\!\,\.]{3,45} is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /[\w\s\-\(\)\!\,\.]{3,45}/: Invalid escape

Thanks for the help!

Casey

Share Improve this question edited Sep 22, 2016 at 0:15 Phil 165k25 gold badges262 silver badges267 bronze badges asked Sep 21, 2016 at 23:58 cphcph 4582 gold badges6 silver badges24 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

Looks valid to me though Chrome does indeed plain.

In any case, you don't need to escape all those characters within a character class. You should be able to use

pattern="[\w\s()!,.-]{3,45}"

which seems to work ok for me.

发布评论

评论列表(0)

  1. 暂无评论