View Full Version : [4.2.0 beta 2] Text field regex validation is too slow in IE9 with some reg exp

4 Feb 2013, 10:18 PM

Ext version tested:

Ext 4.2.0 beta 2

Browser versions tested against:

Chrome - pass
FireFox - pass

DOCTYPE tested against:

<!DOCTYPE html>


Regex validation might be performed too slow in IE9 with some reg exp. It can cause even a browser crash.
There is a small delay even in Chrome. Though, insignificant. So, maybe, is the reg exp too complex? But it doesn't look so.
I understand it might be a weak place in the IE JavaScript engine and you can't do anything here. If so, any recommendations would be appreciated.

Steps to reproduce the problem:

Open the sample in IE9
Type "&" at the end of the text (do not remove the existing text)

The result that was expected:

Smooth validation

The result that occurs instead:

The browsers lags

Test Case:

<!DOCTYPE html>
<title>Regex slow issue</title>

<link rel="stylesheet" href="../resources/css/ext-all.css" />

<script src="../ext-all-debug.js"></script>

Ext.onReady(function () {
Ext.create("Ext.form.field.Text", {
renderTo: Ext.getBody(),
width: 300,
value: "24 pages doc OCR-edocument",
regex: /^([^&/?*:\"|<>\\]+)+$/

4 Feb 2013, 11:37 PM
Moving to Q&A since it's not specific to 4.2 nor a bug report.

There isn't a great deal you can do, it's executing the regex only once, so you're at the mercy of the browser.

4 Feb 2013, 11:42 PM
Also, regexes tend to be a lot slower when you're looking for everything but <x> as opposed to <x>.

See: http://www.regular-expressions.info/catastrophic.html

5 Feb 2013, 2:33 AM
It's pretty spectacular just how slow that regex runs, even in Chrome. But as Evan says, there's not a lot ExtJS can do as it's only running the regex once.

Try changing it to this instead:

regex: /^[^&/?*:\"|<>\\]+$/

As far as I can tell this is equivalent for validation purposes and it runs in a fraction of the time (about 10000 times faster in my Chrome test case). It's that extra + on the end that nukes it and you don't need it. I've also removed the capture group.

5 Feb 2013, 3:07 AM
Evan and @skirtle, thank you for the answers. They are very helpful!

Regular expressions are a bottleneck for me. Shame.