<html>
<head>
</head>
<body>
<div id="error"></div>
<br>
<form id="form">
<input type="text" id="name" maxlength="30"><br>
<input type="text" id="tel" maxlength="10"><br>
<input type="text" id="code" maxlength="5"><br>
</form><br>
<input type="button" value="valiDate" onclick="valiDate();">
<script>
var d = document;
function valiDate() {
var error = d.getElementById("error"), form = d.getElementById("form"), j = true;
error.innerHTML = "";
var num = /^[0-9]*$/;
var abc = /^[a-z A-Z]*$/;
for (i=0; i < form.elements.length; i++) {
switch (form.elements[i].id) {
case "name": {
(form.elements[i].value == "" || abc.exec(form.elements[i].value) == null) ? (error.innerHTML += "Error name<br>", j = false) : "";
break;
}
case "tel": {
(num.exec(form.elements[i].value) == null || (form.elements[i].value.length < 10)) ? (error.innerHTML += "Error tel<br>", j = false) : "";
break;
}
case "code": {
(form.elements[i].value == "" || form.elements[i].value.length < 5) ? (error.innerHTML += "Error code<br>", j = false) : "";
break;
}
}
}
j == true ? alert("ok") : alert("error");
}
</script>
</body>
</html>