The input pattern does not completely match IE11, but in Chrome, FF

The following input field is fully validated in Chrome and FF, but only partially in IE11.

<input name="bic" value="" type="text" title="BIC-Code" required pattern="[AZ]{6}[A-Z2-9][A-NP-Z0-2](|[A-WY-Z0-9][A-Z0-9]{2}|X{3})" > 

Testing code with an 8-character BIC always works in any browser. Testing it with 11 characters causes an error in IE.

Current version: 11.0.9600.17959, updateversion: 11.0.22

Examples:

  • 6 characters are valid in all browsers: RBOSGGSX
  • 11 characters are valid in all browsers except IE: GENODEF1S04

Questions:

  • Is there a bug in IE (maybe)?
  • Are there any restrictions on using regex in IE?
  • Am I making a mistake that Chrome and FF ignore?

The only thing Google finds is the problem type='number' "with ^[0-9]*$ .

http://www.w3.org/TR/2011/WD-html5-20110525/common-input-element-attributes.html#the-pattern-attribute says:

This means that the regular expression language used for this attribute is the same as in JavaScript, except that the pattern attribute must match the entire value, and not just any subset (several, as if it meant a ^ (?: at the beginning of the figure and a) $ at the end).

Even the Javascript-Engine correctly checks in IE11:

 new RegExp("^[AZ]{6}[A-Z2-9][A-NP-Z0-2](|[A-WY-Z0-9][A-Z0-9]{2}|X{3})$").test("GENODEF1S04"); 
+5
source share
1 answer

It seems IE11 cannot handle interleaving where the first branch is empty. It:

 (|[A-WY-Z0-9][A-Z0-9]{2}|X{3}) 

... should be equivalent to this:

 ((?:[A-WY-Z0-9][A-Z0-9]{2}|X{3})??) 

... the value of [A-WY-Z0-9][A-Z0-9]{2} or X{3} or nothing, while "nothing" is not the first (or preferred) option.

I recommend not using the "or nothing" idiom, even with an empty branch at the end (which seems to work in IE11). This is not very common, and I think that an extra group will do better with your intentions.

+2
source

All Articles