<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
//是否为空正则表达式
var reg=/^\s*$/;
//邮箱正则表达式
var reg1=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
function check(){
var f1=checkNotNull("username","用户名");
var f2=checkNotNull("mima","密码");
var f3=checkNotNull("remima","确认密码");
var f4=checkemail("email","电子邮箱");
if(f2&&f3){
var v=document.getElementById("mima").value;
var v2=document.getElementById("remima").value;
if(v!=v2){
alert("密码不一致");
return false;
}
}
return f1&&f2&&f3;
}
//检验是否为空
function checkNotNull(id,name){
//通过id获取input对象
var v=document.getElementById(id);
//获取value值
var val=v.value;
//判定数据是否为空
if(reg.test(val)){
alert(name+"不能为空");
return false;
}
return true;
}
//检验邮箱
function checkemail(id,name){
var v=document.getElementById(id);
var e=v.value;
if(!reg1.test(e)){
alert("邮箱格式不正确")
return false;
}
return true;
}
</script>
</head>
<body>
<form action="" method="get" onsubmit="check()">
<table width="60%">
<tr>
<td colspan="3">
<font size="5"color="aqua">会员注册</font>
<font size="5"><b>USER REGISTER</b></font>
</td>
</tr>
<tr>
<td align="right">用户名</td>
<td colspan="2">
<input type="text"name="username"id="username"size="60"/>
</td>
</tr>
<tr>
<td align="right">密码</td>
<td colspan="2">
<input type="password"name="mima"id="mima"size="60" />
</td>
</tr>
<tr>
<td align="right">确认密码</td>
<td colspan="2">
<input type="password"name="remima"id="remima"size="60" />
</td>
</tr>
<tr>
<td align="right">电子邮箱</td>
<td colspan="2">
<input type="text"name="email"id="email"size="60" />
</td>
</tr>
</table>
</form>
</body>
</html>
Html页面,手机及密码长度正则表达式自己查查加上就OK