简体   繁体   中英

Regex Case Insensitive with input match

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 ?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM