问题
I am trying to make validation for an html input by assigning via javascript a regex using the following code:
$("#"+field.field_id).attr("data-validation",'custom');
$("#"+field.field_id).attr("data-validation-regexp",field.regex);
If I set the regex to
^(Server (\d{1,2}))$
Then it works only with input 'Server ..' But i want the input Server to work with case insensitive. Like 'SERVER' or 'sErver'...... I tried to put ^(Server (\d{1,2}))$/i but it doesn't work. Any ideas ?
回答1:
You can use:
^([Ss][Ee][Rr][Vv][Ee][Rr] (\d{1,2}))$
to make it case insensitive.
There is no support of i (ignore case flag) in input pattern since it is compiled with the global, ignoreCase, and multiline flags disabled.
回答2:
This doesn't work, because you're not using open slash for regex:
^(Server (\d{1,2}))$/i
But this should work:
/^(Server (\d{1,2}))$/i
来源:https://stackoverflow.com/questions/27858038/regex-case-insensitive-with-input-match