简单验证

2010-3-6 杜世伟 JavaScript

<!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=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
function checkmsg(){
var str = document.getElementById("name").value;
if(document.form1.name.value==""){
alert("请输入您的姓名!");
document.form1.name.focus();
return false;
}
if(str.length < 5){  
alert("至少输入5个字符!");
}else if(str.length > 20){  
alert("不能超过20个字符!");
str = str.substring(0,20);  
document.getElementById("test").value = str.substring(0,20); }
if(document.form1.password.value==""){
alert("请输入您的密码!");
document.form1.password.focus();
return false;
}
if(document.form1.passwd.value==""){
alert("请输入再次输入密码!");
document.form1.passwd.focus();
return false;
}
if(document.form1.password.value!=(document.form1.passwd.value)){
alert("前后密码不一致请重新输入!");
return false;
}
return true;
}
</script>
</head>

<body bgcolor="#CC66FF">
<form id="form1" name="form1" method="post" onsubmit="return checkmsg();" enctype="multipart/form-data">
<table width="443" align="center">
    <tr>
      <td>姓名;</td>
      <td><input type="text" name="name" id="name"/></td>
    </tr>
    <tr>
      <td>密码;</td>
      <td><input type="password" name="password" /></td>
    </tr>
    <tr>
      <td>确认密码;</td>
      <td><input type="password" name="passwd" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" value="提交" />
   <input type="reset" value="重置" /></td>
    </tr>
</table>
</form>
</body>
</html>

Powered by emlog 沪ICP备2023034538号-1