<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/reg.js"></script>
<script type="text/javascript">
function checkPhone()
{
var phone = document.getElementById("phone").value;
var phone_prompt = document.getElementById("phone_prompt");
var reg = /^\d{3,4}-\d{7,8}$/;
if(reg.test(phone) == false){
phone_prompt.innerHTML = "输入的电话号码格式不正确";
}
}
</script>
</head>
<body>
<div id="main" style="border:1px solid #F00">
<table align="center" style="border:1px solid #00F">
<form action="" method="post" name="myform" οnsubmit="return check();">
<tr>
<td class="left">Email:</td>
<td><input type="text" id="email" class="inputs" οnblur="checkEmail();" /><span id="emailMsg"></span></td>
</tr>
<tr>
<td class="left">输入密码:</td>
<td><input type="password" id="pwd" class="inputs" /></td>
</tr>
<tr>
<td class="left">请再输入一遍:</td>
<td><input type="password" id="repwd" class="inputs" /></td>
</tr>
<tr>
<td class="left">电话号码:</td>
<td><input type="text" id="phone" class="inputs" οnblur="checkPhone();" /><div id="phone_prompt"></div></td>
</tr>
<tr>
<td><input type="submit" value="提交" /></td>
</tr>
</form>
</table>
</div>
</body>
</html>
对应的文件夹js下的reg.js:
// JavaScript Document
function $(id){
document.getElementById(id);
}
function check()
{
var email = document.getElementById("email").value;
if(email == ""){
alert("邮箱名不能为空");
return false;
}
if(email.indexOf("@") ==- 1 || email.indexOf(".") == -1){
alert("邮箱格式不正确,必须包含@和“.”");
return false;
}
var pwd = document.getElementById("pwd").value;
if(pwd == ""){
alert("密码不能为空");
return false;
}
if(pwd.length < 6){
alert("密码不能小于六位");
return false;
}
var repwd = document.getElementById("repwd").value;
if(repwd != pwd){
alert("两次输入的密码不一致");
return false;
}
}
function checkEmail(){
alert("checkEmail");
var email = document.getElementById("email").value;
if(email == ""){
document.getElementById("emailMsg").innerHTML = "Email地址不能为空";
return false;
}
if(email.indexOf("@") ==- 1 || email.indexOf(".") == -1){
document.getElementById("emailMsg").innerHTML = "邮箱格式不正确,必须包含@和'.'";
return false;
}
}