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

This was just working a day ago but now throwing exception.I've pasted regex into online verifie

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744710656a4589322.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信