-
4 Feb 2013 10:18 PM #1
Answered: [4.2.0 beta 2] Text field regex validation is too slow in IE9 with some reg exp
Answered: [4.2.0 beta 2] Text field regex validation is too slow in IE9 with some reg exp
REQUIRED INFORMATION
Ext version tested:- Ext 4.2.0 beta 2
- IE9 - FAIL
- Chrome - pass
- FireFox - pass
- <!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.
- Open the sample in IE9
- Type "&" at the end of the text (do not remove the existing text)
- Smooth validation
- The browsers lags
Code:<!DOCTYPE html> <html> <head> <title>Regex slow issue</title> <link rel="stylesheet" href="../resources/css/ext-all.css" /> <script src="../ext-all-debug.js"></script> <script> Ext.onReady(function () { Ext.create("Ext.form.field.Text", { renderTo: Ext.getBody(), width: 300, value: "24 pages doc OCR-edocument", regex: /^([^&/?*:\"|<>\\]+)+$/ }); }); </script> </head> <body> </body> </html>
-
Best Answer Posted by skirtle
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:
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.Code:regex: /^[^&/?*:\"|<>\\]+$/
-
4 Feb 2013 11:37 PM #2Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,103
- Vote Rating
- 97
- Answers
- 170
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.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
4 Feb 2013 11:42 PM #3Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,103
- Vote Rating
- 97
- Answers
- 170
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.htmlEvan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
5 Feb 2013 2:33 AM #4
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:
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.Code:regex: /^[^&/?*:\"|<>\\]+$/
-
5 Feb 2013 3:07 AM #5


Reply With Quote