标签:style http color java 使用 os io for
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>check form</title>
<script type="text/javascript">
function checkUsername(){
var sp = document.getElementById("s_username");
var username = document.getElementById("username").value.trim();
if(username ==""){
sp.innerHTML="用户名不能为空";
return false;
}
if(username.length<6){
sp.innerHTML="用户名必须大于6位";
return false;
}
sp.innerHTML="用户名正确";
return true;
}
function checkPwd1(){
var sp = document.getElementById("s_password");
var pwd1 = document.getElementById("password1").value.trim();
if(pwd1 == ""){
sp.innerHTML = "密码不能为空";
return false;
}
if(pwd1.length<6){
sp.innerHTML = "密码必须是6为以上的字母和数字";
}else{
sp.innerHTML = "密码正确";
return true;
}
}
function checkPwd2(){
var sp = document.getElementById("s_password2");
var pwd1 = document.getElementById("password1").value;
var pwd2 = document.getElementById("password2").value.trim();
if(pwd2==""){
sp.innerHTML = "请输入确认密码";
return false;
}
if(pwd2 != pwd1){
sp.innerHTML = "两次密码不一致";
}else{
sp.innerHTML = "密码正确";
return true;
}
}
function checkEmail(){
var email = document.getElementById("email").value.trim();
if(email == ""){
alert("邮箱不能为空");
return false;
}
var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
isok = reg.test(email);
if(!isok){
alert("邮箱格式不对");
email="";
return false;
}else{
alert("邮箱格式对");
return true;
}
}
function checkForm(){
var name = checkUsername();
var pwd2 = checkPwd2();
var email = checkEmail();
var isok = name && pwd2 && email;
return isok;
}
</script>
</head>
<body>
<div id="regist">
<form action="index.html" method="post" onsubmit="return checkForm()">
<span style="color: red;">*</span>用 户 名:<input type="text" name="username" id="username" onkeyup="checkUsername()"><br>
<span id="s_username" style="color: red;font-size: 12px">6~18个字符,可使用字母、数字、下划线,需以字母开头</span><br>
<span style="color: red;">*</span>密 码:<input type="password" name="password1" id="password1" onkeyup="checkPwd1()">
<span id="s_password" style="color: red;">密码必须是6为以上的字母和数字</span><br>
<span style="color: red;">*</span>确认密码:<input type="password" name="password2" id="password2" onblur="checkPwd2()">
<span id="s_password2" style="color: red;"></span><br>
<span style="color: red;">*</span>邮 箱:<input type="text" name="email" id="email" onblur="checkEmail()">
<span id="s_email" style="color: red;"></span><br>
性 别:<input type="radio" name="gender" id="gender">男
<input type="radio" name="gender" id="gender">女<br>
<input type="submit" value="立即注册">
</form>
</div>
</body>
</html>
标签:style http color java 使用 os io for
原文地址:http://www.cnblogs.com/siashan/p/3924228.html