javascriptの使用(6)formvalidフォームの検証
1575 ワード
<html>
<head>
<title> </title>
<script type="text/javascript">
function valid(){
var username=document.getElementById("username");
if(username.value==""){
alert(" ");
return;
}
if(username.value.length<6){
alert(" 6 ");
return;
}
var email=document.getElementById("email");
var atIndex=email.value.indexOf("@");
var dotIndex=email.value.indexOf(".");
if(atIndex==-1 || dotIndex==-1){
alert(" @ . ");
return;
}
if(atIndex>dotIndex){
alert("@ . ");
return;
}
if(dotIndex-atIndex==1){
alert("@ . ");
return;
}
var registerForm=document.getElementById("registerForm");
//
registerForm.submit();
}
</script>
</head>
<body>
<form id="registerForm" action="http://www.baidu.com" method="post" >
:<input type="text" name="username" id="username" />
<br/>
:<input type="password" name="password" id="password" />
<br/>
:<input type="password" name="check_password" id="check_password" />
<br/>
:<input type="text" name="email" id="email" />
<br/>
<input type="button" value=" " />
</form>
</body>
</html>