如下所示:
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>在此处插入标题</title>
<script type="text/javascript">
//判断用户输入的电子邮箱格式是否正确
function checkemail(){
var myforms=document.forms;
var myemail=myforms[0].email.value;
var myreg=/^[a-za-z0-9_-]+@([a-za-z0-9]+\.)+(com|cn|net|org)$/;
if(myreg.test(myemail)){
return true;
}else{
myspan.innertext="邮箱格式不对!";
return false;
}
}
</script>
</head>
<body>
<form action="#">
<table>
<tr><td>邮箱:<input type="text" id=email></td><td><span id=myspan style="text-size:18pt;color:red;"></span></td></tr>
<tr><td><input type="submit" value="提交" onclick="return checkemail()"/></td><td></td></tr>
</table>
</form>
</body>
</html>
