Reputation: 46841
I have a div as defined below:
<div id="bookmark_error" class="text-error">Character '' is not allowed in bookmark name.</div>
By default it is hidden as defined below:
$("#bookmark_error").hide();
Some of characters are not allowed while saving bookmark on a page for e.g. < and >
Here a validation check that is performed at the time of bookmark save:
...
var bookmark_name = $("#bookmarks-form").find('input[type=text]').val();
var skipChars = ["<", ">", "<", ">", "<", ">", "<", ">", "<", ">"];
for (var i=0; i < skipChars.length; i++){
var skipChar = skipChars[i];
while(bookmark_name.indexOf(skipChar) != -1){
$("#bookmark_error").html($("#bookmark_error").html().replace(/'[^]*'/g, "'"+skipChar+"'"));
$("#bookmark_error").show();
return;
}
}
...
But its not working as expected in IE8 browser. Am I doing something wrong in javascript regex?
Here is some sample value-input-value:
value : Character '' is not allowed in bookmark name.
input : <
value : Character '<' is not allowed in bookmark name.
input : >
output : Character '>' is not allowed in bookmark name.
Upvotes: 1
Views: 217
Reputation: 2344
You need to add \d
in your regex for it to work on ie8
Reference from : RegEx not working in IE8
So your code will look like this
$("#bookmark_error").html($("#bookmark_error").html().replace(/'[^\d]*'/g, "'"+skipChar+"'"));
Upvotes: 1