📌  相关文章
📜  如何在javascript代码示例中阻止特殊字符

📅  最后修改于: 2022-03-11 15:02:45.378000             🧑  作者: Mango

代码示例2
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

for (var i = 0; i < document.formname.fieldname.value.length; i++) {
    if (iChars.indexOf(document.formname.fieldname.value.charAt(i)) != -1) {
        alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
        return false;
    }
}