Uncaught SyntaxError: Invalid regular expression

2019-09-11 01:43发布

问题:

I am trying to validate an input field using the following pattern but i get this error :

<input id="testMyU" type="text" required maxlength=35 pattern="((?!((&[^\ ]*;))|([<>])).)*" >

Error :

Pattern attribute value ((?!((&[^\ ]*;))|([<>])).)* is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /((?!((&[^\ ]*;))|([<>])).)*/: Invalid escape

I don't find my mistake ...

回答1:

Your problem is here:

<input id="testMyU" type="text" required maxlength=35 pattern="((?!((&[^\ ]*;))|([<>])).)*" >
                                                                        ^

Try using a double backslash.