我想通过输入特殊字符验证用户名输入字段:
!`@#$%^&*()+=-[]\\\';,./{}|\":<>?~_
这是我的代码:
function specialcharecter()
{
var iChars = "!`@#$%^&*()+=-[]\\\';,./{}|\":<>?~_";
var data = document.getElementById("txtCallSign").value;
for (var i = 0; i < data.length; i++)
{
if (iChars.indexOf(data.charAt(i)) != -1)
{
alert ("Your string has special characters. \nThese are not allowed.");
document.getElementById("txtCallSign").value = "";
return false;
}
}
}