输入模式在 IE11 中不完全匹配,但在 Chrome 中,FF
Input pattern doesn't match completely in IE11, but in Chrome, FF
以下输入字段在 Chrome 和 FF 中完全有效,但在 IE11 中仅部分有效。
<input name="bic" value="" type="text" title="BIC-Code" required
pattern="[A-Z]{6}[A-Z2-9][A-NP-Z0-2](|[A-WY-Z0-9][A-Z0-9]{2}|X{3})"
>
使用 8 个字符的 BIC 测试代码始终适用于任何浏览器。用 11 个字符测试它会在 IE 中产生错误。
当前安装版本:11.0.9600.17959,更新版本:11.0.22
示例:
- 6 个字符在所有浏览器中均有效:
RBOSGGSX
- 11 个字符在除 IE 之外的所有浏览器中均有效:
GENODEF1S04
问题:
- IE 中是否存在错误(可能)?
- 在 IE 中使用正则表达式是否存在已知限制?
- 我是否犯了一个 Chrome 和 FF 忽略的错误?
Google 唯一找到的是 type='number'
"problem" 和 ^[0-9]*$
。
This implies that the regular expression language used for this
attribute is the same as that used in JavaScript, except that the
pattern attribute must match the entire value, not just any subset
(somewhat as if it implied a ^(?: at the start of the pattern and a )$
at the end).
甚至 Javascript-Engine 在 IE11 中也能正确验证:
new RegExp("^[A-Z]{6}[A-Z2-9][A-NP-Z0-2](|[A-WY-Z0-9][A-Z0-9]{2}|X{3})$").test("GENODEF1S04");
IE11 似乎无法处理第一个分支为空的交替。这个:
(|[A-WY-Z0-9][A-Z0-9]{2}|X{3})
...应该等同于:
((?:[A-WY-Z0-9][A-Z0-9]{2}|X{3})??)
...意思是 [A-WY-Z0-9][A-Z0-9]{2}
或 X{3}
或什么都不是,"nothing" 是第一个(或首选)选项。
我建议不要使用 "or nothing" 习语,即使末尾有空分支(这在 IE11 中似乎工作正常)。这不是很常见,我认为可选组可以更好地传达您的意图。
以下输入字段在 Chrome 和 FF 中完全有效,但在 IE11 中仅部分有效。
<input name="bic" value="" type="text" title="BIC-Code" required
pattern="[A-Z]{6}[A-Z2-9][A-NP-Z0-2](|[A-WY-Z0-9][A-Z0-9]{2}|X{3})"
>
使用 8 个字符的 BIC 测试代码始终适用于任何浏览器。用 11 个字符测试它会在 IE 中产生错误。
当前安装版本:11.0.9600.17959,更新版本:11.0.22
示例:
- 6 个字符在所有浏览器中均有效:
RBOSGGSX
- 11 个字符在除 IE 之外的所有浏览器中均有效:
GENODEF1S04
问题:
- IE 中是否存在错误(可能)?
- 在 IE 中使用正则表达式是否存在已知限制?
- 我是否犯了一个 Chrome 和 FF 忽略的错误?
Google 唯一找到的是 type='number'
"problem" 和 ^[0-9]*$
。
This implies that the regular expression language used for this attribute is the same as that used in JavaScript, except that the pattern attribute must match the entire value, not just any subset (somewhat as if it implied a ^(?: at the start of the pattern and a )$ at the end).
甚至 Javascript-Engine 在 IE11 中也能正确验证:
new RegExp("^[A-Z]{6}[A-Z2-9][A-NP-Z0-2](|[A-WY-Z0-9][A-Z0-9]{2}|X{3})$").test("GENODEF1S04");
IE11 似乎无法处理第一个分支为空的交替。这个:
(|[A-WY-Z0-9][A-Z0-9]{2}|X{3})
...应该等同于:
((?:[A-WY-Z0-9][A-Z0-9]{2}|X{3})??)
...意思是 [A-WY-Z0-9][A-Z0-9]{2}
或 X{3}
或什么都不是,"nothing" 是第一个(或首选)选项。
我建议不要使用 "or nothing" 习语,即使末尾有空分支(这在 IE11 中似乎工作正常)。这不是很常见,我认为可选组可以更好地传达您的意图。