Check For Special Characters in JavaScript
by Rekha[ Edit ] 2009-11-07 15:18:35
You can use the below code to check special characters in javascript.
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~_";
for (var i = 0; i < name.length; i++) {
if (iChars.indexOf(name.charAt(i)) != -1) {
alert ("Your string has special characters. \nThese are not allowed.");
return false;
}
}