javascript - Invalid regular expression in HTML5 input pattern -


i need use regular expression in html input (taken regular expression list of items separated comma or comma , space):

[^,\s][^\,]*[^,\s]* 

so set in input:

<input type="text" class="form-control" id="input" name="input" data-ng-model="mymodel" pattern="[^,\s][^\,]*[^,\s]*"> 

but error in console:

pattern attribute value [^,\s][^\,]*[^,\s]* not valid regular expression: uncaught syntaxerror: invalid regular expression: /[^,\s][^\,]*[^,\s]*/: invalid escape 

what wrong regex?

i'm using angular 1.5 btw.

you need remove escaping backslash before comma , use

 pattern="[^,\s][^,]*[^,\s]*" 

it necessary since ff , chrome compile pattern regex using es6 regex syntax specifications, , use /u modifier when compiling regexp object. lays restrictions on pattern. in case, regular symbol, not special metacharacter, comma, escaped inside character class. thus, removing escape solves issue.

input:valid {    color: black;    border: 5px solid #dadadada;    border-radius: 7px;  }  input:invalid {    color: navy;    outline: none;     border-color: #ff1050;    box-shadow: 0 0 10px #ff0000;  }
<form>    <input type="text" class="form-control" id="input" name="input" data-ng-model="mymodel" pattern="[^,\s][^,]*[^,\s]*">  </form>


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -