我想成为至少 8 个字符且年龄大于 16 的有效输入文本,并使用 Javascript 中的函数排除一些图标
function validate() {
//Make a selector pointing to your input first
var myInput = document.getElementById('yourInputId').value
//Validate length:
if (myInput.length >= 8) {
//Check for age
if (eval(myInput) >= 16) {
alert('your input is ok!');
}
else {
alert('Minimum age is 16!');
}
}
else {
alert('input too short!');
}
}
PS:对于字符排除,您应该跳转到正则表达式
(网络上有大量的例子,只是谷歌它!