1

我想通过输入特殊字符来验证用户名输入字段:

!`@#$%^&*()+=-[]\\\';,./{}|\":<>?~_

这是我的代码:

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; 
        } 
    }
}
4

0 回答 0