I faced this issue when i was working on IE 8 and this issue has driven me crazy.Since this is not a straight forward issue to fix, i tried to narrow down the problem and finally came to know the regular expression what i used for validation is the culprit for this.This issue would not have come if you are running your application in the high end browsers.
The line which was causing the problem -
It works like a charm !!
The line which was causing the problem -
var SpecialCharRegex = /^[0-9a-zA-Z',-\s]*$/;After doing lot of googling i found the issue and the issue is "-" in this regular expression.This error is due to the hyphen, which is mistakenly being used to represent a range and is not properly escaped. To fix this lets add backslash before "-" and change the regular expression like this -
var SpecialCharRegex = /^[0-9a-zA-Z',\-\s]*$/;
Simple logic is either put "-" at the beginning or end of the character class or use backslash to do a regex escape.It works like a charm !!
This solved my problem
ReplyDeleteThanks for commenting. I am glad to hear that.
DeleteI still get that error even if I DO escape the "-" character with backslash.
ReplyDeleteIf I move the "-" to the beginning.... the problem disappears.
But why???
I still get that error even if I DO escape the "-" character with backslash -
DeleteAbhijith - Can you paste the regex what you are trying to use ?
If I move the "-" to the beginning.... the problem disappears.
Abhijith - Correct. If you add it at the beginning it is being treated as "Hyphen" else it is treated as "Range".