admin管理员组

文章数量:1391981

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.

本文标签: javascriptWhy isn39t this a valid regular expressionStack Overflow