Why is this not a valid regular expression?

It was just working a day ago, but now throws an exception. I put a regex in the 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}"> 

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

Thanks for the help!

Casey

+5
source share
1 answer

Looks in my favor, although Chrome really complains.

In any case, you do not need to avoid all of these characters in the character class. You should be able to use

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

which seems to work fine for me.

+6
source

All Articles