Check For Special Characters in JavaScript

by Rekha 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;
}
}

Tagged in:

1123
like
0
dislike
0
mail
flag

You must LOGIN to add comments