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
The static Regex. Match method returns a single Match object. By using this static method to run a regular expression against a string (in this case a blank string), we can determine whether the regular expression is invalid by watching for a thrown exception.
In short regular expressions does not allow the pattern to refer to itself. You cannot say: at this point in the syntax match the whole pattern again. To put it another way, regular expressions only matches linearly, it does not contain a stack which would allow it to keep track of how deep it is an a nested pattern.
A regex (regular expression) consists of a sequence of sub-expressions. In this example, [0-9] and + . The [...] , known as character class (or bracket list), encloses a list of characters. It matches any SINGLE character in the list.
Inductive Rule 1: If A and B are regular expressions, then A B matches concatenations of A and B . Inductive Rule 2: If A and B are regular expressions, then A | B is a regular expression that matches stands matched by either A or B .
Looks valid to me though Chrome does indeed complain.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With