让HTML5的输入模式属性忽略大小写 [英] Have HTML5's a inputs pattern attribute ignore case
问题描述
我需要让HTML的输入元素模式忽略值的情况,
就像正则表达式是/ [az] * /我可以让它匹配所有大写字母吗? >
(我知道我可以做/ [a-zA-Z] * /,但这只是一个例子。)
-
-
该模式使用ECMAScript(即Javascript)的正则表达式风格
- p>它是通过全局,ignoreCase和多行标志 禁用 编译的。
> -
-
在Javascript中,使正则表达式忽略大小写的唯一方法是在外部设置修饰符(
/.../我
)。不支持PCRE语法(?i)
。 The specification on
<input pattern>
[1,2] specifies thatthe pattern uses the ECMAScript (i.e. Javascript) flavor of regex
it is compiled "with the global, ignoreCase, and multiline flags disabled"
In Javascript, the only way to make a regex ignore case is to set the modifier externally (
/.../i
). The PCRE syntax(?i)
is not supported.
因此,模式始终区分大小写和 [a-zA-Z] *
(即使正则表达式本身明确区分大小写)是以不区分大小写的方式匹配模式的唯一方法。
I need to have HTML's input elements pattern ignore the case of the value,
like have if the regex is /[a-z]*/ could I get it to match all uppercase letters too?
(I know I could just do /[a-zA-Z]*/, but that was an example.)
I don't think it is possible.
Therefore, the pattern is always case-sensitive and [a-zA-Z]*
(i.e. making the regex itself explicitly case insensitive) is the only way to match the pattern in a case-insensitive way.
这篇关于让HTML5的输入模式属性忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!