日期:2014-05-16 浏览次数:20445 次
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <script type="text/javascript"> function validate(){ var userName=document.getElementById("userName").value; var userEmail=document.getElementById("userEmail").value; var userAge=document.getElementById("userAge").value; if(userName.length < 4 || userName.length > 16){ alert("请输入大于4个字符小于16的个字符的名字"); return false; } if(userEmail.search("^(?:\\w+\\.?)*\\w+@(?:\\w+\\.?)*\\w+$")!=0){ alert("请输入正确的Email格式"); return false; } if(isNaN("userAge")="false" && (userAge < 1 || userAge > 150) ){ alert("请输入正确的年龄"); return false; } } </script> <body> </body> <form action="/" method="post"> 姓名:<input type="text" id="userName" /><br /> Email:<input type="text" id="userEmail" /><br /> 年龄:<input type="text" id="userAge" /><br /> <input type="submit" onclick="return validate()" /> </form> </html>
if(userAge.length==0 || (userAge < 1 || userAge > 150) ){ alert("请输入正确的年龄"); return false; }