简单验证
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> </td>
<td><input type="submit" name="submit" value="提交" />
<input type="reset" value="重置" /></td>
</tr>
</table>
</form>
</body>
</html>
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(18)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(72)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)