<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312"/>
<style type="text/css"></style>
<script type="text/javascript">
</script>
</head>
<body>
<form action="." method="post" οnsubmit="return register()">
name:<input id="name" type="text" placeholder="请输入用户名"/>
age:<input id="age" type="text" placeholder="请输入年纪"/>
email:<input id="email" type="text" placeholder="请输入email"/>
<input type="submit" value="提交"/>
</form>
<script type="text/javascript">
function register(){
var name = document.getElementById("name");
if(name.value.length<=3){
confirm("用户名长度不低于3");
return false;
}
var age = document.getElementById("age");
if(isNaN(age.value)){
confirm("age只能是数字");
return false;
}
if(parseInt(age.value)!=age.value){
confirm("age只能是整数");
return false;
}
var email = document.getElementById("email");//获得邮箱输入框对象
if(email.value.length==0){
confirm("邮箱不可为空");
return false;
}
//邮箱正则表达式
var regex = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
//判断
if(!regex.test(email.value)){
confirm("邮箱格式不正确");
return false;
}
return true;
}
</script>
</body>
</html>
js常用,邮箱的验证
最新推荐文章于 2024-08-26 08:56:58 发布