Hey everybody,
I am trying to replace all special characters except alphanumerics using js.
function checkWholeString(string,len){
if(string != null && string != ""){
var regExp = /^[A-Za-z0-9-]+$/;
for(var i=0; i < string.length; i++){
var ap = string.charAt(i);
if(!ap.match(regExp)){
string = string.replace(ap," ");
}
}
return jQuery.trim(string);
}
}
trouble is when I am holding for example "a" key pressed and while I am still holding it I will press another key it will add blank spaces to the text.
Is there any chance to improve the code to get rid of this? Any help would be most welcome.
Thanks Pete