这是我的代码验证特殊字符不工作
<!DOCTYPE html>
<html>
<script>
function isSpclChar() {
var iChars = "[email protected]#$%^&*()+=-[]\\\';,./{}|\":<>?";
if (document.getElementById('edit_tagline').value.indexOf(iChars) != -1) {
alert("The box has special characters. ");
} else {
alert("No special character");
}
}
</script>
<body>
<input type="text" id="edit_tagline" onblur="isSpclChar()">
</body>
</html>
我的第一个问题是,为什么这种验证是不工作?
我的第二个问题是,任何人可以解释我的意思这条线
if(document.getElementById('edit_tagline').value.indexOf(iChars) != -1)
的,因为我是新来的JavaScript和复制粘贴代码从什么地方我不知道它的工作。
那么,如果有人能解释我这个代码的工作好吗?
iChars不是一个字符范围,它将其视为一个单词。你将需要实现一个正则表达式才能做到这一点。 – brandonscript
@remus你能告诉我如何? – TruePS