Validate Special Character

Rajni.Shekhar
Posted by Rajni.Shekhar under JavaScript category on | Points: 40 | Views : 1343
function ValidateSpecialChar(fieldID, fieldName) //fieldID id of field, and fieldName name of the field
{

var fieldval = fieldID.value;
if (fieldval != "") {
var iChars = "!~@'#$%^*+=[]\\\;,/{}|\":<>?";
for (var i = 0; i < fieldval.length; i++) {
if (iChars.indexOf(fieldval.charAt(i)) != -1) {
alert(fieldName+ " cannot contain special characters or the symbols.");
fieldID.select();
fieldID.focus();
return false;
}
}
}

}

Comments or Responses

Login to post response