自己写的js验证例子,不满足条件时会有文字提示的!不用alert!
2011-05-14 12:23
141 查看
<script type="text/javascript">
function check(obj){
if(obj.value.length < 6 || obj.value.length > 16) {
document.getElementById("errorinfo").style.display = "block";
[color=red] document.getElementById("submit").disabled = true;[/color]
}
else {
document.getElementById("errorinfo").style.display = "none";
[color=red] document.getElementById("submit").disabled = false;[/color]
}
}
function checkPwd(obj)
{
if (obj.value.length < 6 || obj.value.length > 16) {
document.getElementById("errorpwd").style.display = "block";
document.getElementById("submit").disabled = true;
}
else {
document.getElementById("errorpwd").style.display = "none";
document.getElementById("submit").disabled = false;
}
}
function checkRePwd(obj)
{
var p=document.getElementById("password");
if(obj.value.length<6||obj.value.length>16)
{
document.getElementById("errorrepwd1").style.display = "block";
document.getElementById("submit").disabled = true;
}
if (p.value != obj.value) {
document.getElementById("errorrepwd2").style.display = "block";
document.getElementById("submit").disabled = true;
}
else {
document.getElementById("errorrepwd1").style.display = "none";
document.getElementById("errorrepwd2").style.display = "none";
document.getElementById("submit").disabled = false;
}
}
function checkemail(obj)
{
var cEmail=obj.value;
if(cEmail.match(/[\w-]+@{1}[\w-]+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig)!=cEmail){
document.getElementById("erroremail").style.display = "block";
document.getElementById("submit").disabled = true;
}
else{
document.getElementById("erroremail").style.display = "none";
document.getElementById("submit").disabled = false;
}
}
function checkqq(obj){
var q=obj.value;
var filter=/^\s*[.0-9]{5,10}\s*$/;
if(!filter.test(q)){
document.getElementById("errorqq").style.display = "block";
}else{
document.getElementById("errorqq").style.display = "none";
}
}
</script>
<link href="<%=request.getContextPath()%>/style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#CCCCCC" >
<p style="color:#FF0000" align="center">温馨提示:带"*"为必填内容</p>
<form name="form1" method="post" action="servlet/RegisterServlet" >
<table width="41%" height="300" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<tr bgcolor="#FFFFFF">
<td height="27" colspan="2" align="center" background="images/table.gif"><strong><font color="#FFFFFF">欢迎加入</font></strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="19%" height="27" align="center">账号:</td>
<td width="81%" height="27"><input name="username" type="text" id="username" onblur="check(this)"/>
* <div style="display:none" id="errorinfo">账号长度必须在6至16个字符之间</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="19%" height="27" align="center">密码:</td>
<td width="81%" height="27"><input name="password" type="password" id="password" onblur="checkPwd(this)"/>
* <div style="display:none" id="errorpwd">密码长度必须在6至16个字符之间</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="19%" height="27" align="center">再次输入密码:</td>
<td width="81%" height="27"><input name="rePassword" type="password" id="rePassword" onblur="checkRePwd(this)" />
*
<div style="display:none" id="errorrepwd1">两次输入密码不一致</div>
<div style="display:none" id="errorrepwd2">密码长度必须在6至16个字符之间</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="27" align="center">性别:</td>
<td height="27"><select name="sex" id="sex">
<option value="男" selected>男</option>
<option value="女">女</option>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="27" align="center">邮件:</td>
<td height="27"><input name="email" type="text" id="email" onblur="checkemail(this)"/>*
<div style="display:none" id="erroremail">输入邮箱格式有误</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="31" align="center">QQ:</td>
<td height="31"><input name="qq" type="text" id="qq" onblur="checkqq(this)" />
<div style="display:none" id="errorqq">请输入正确的qq</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="31" align="center">头象:</td>
<td height="31"><input name="tx" type="radio" value="images/face01.gif" checked>
<img src="<%=basePath%>images/face01.gif" width="32" height="32">
<input type="radio" name="tx" value="images/face02.gif">
<img src="<%=basePath%>images/face02.gif" width="32" height="32">
<input type="radio" name="tx" value="images/face03.gif">
<img src="<%=basePath%>images/face03.gif" width="32" height="32"> <br>
<input type="radio" name="tx" value="images/face04.gif">
<img src="<%=basePath%>images/face04.gif" width="32" height="32">
<input type="radio" name="tx" value="images/face05.gif">
<img src="<%=basePath%>images/face05.gif" width="32" height="32">
<input type="radio" name="tx" value="images/face06.gif">
<img src="<%=basePath%>images/face06.gif" width="32" height="32"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="31" colspan="2" align="center">
[color=red]<input type="submit" value="提交" id="submit" style="width:50px" disabled="disabled"/>[/color]
<input style="width:50px;" type="reset" value="重置"/>
<input style="width:50px;" type="button" value="返回" onClick="window.location.href='http://localhost:8080/lastuse/servlet/QueryServlet'">
</td>
</tr>
</table>
</form>
:evil: 效果图如下 阅读更多
相关文章推荐
- 自己写的js验证例子,不满足条件时会有文字提示的!不用alert!
- 用js验证输入信息,不使用alert,而使提示错误的信息直接出现在输入框后?在同一行上
- 数据操作后,页面alert提示例子3-后台js打印提示信息并重定向
- 自己工作中 整理的常用到的JS 验证(包括例子)
- 一款非常好用的boostrap的验证插件、再也不用自己手写正则表达式和js了
- js 鼠标点击文本框 提示文字消失 (小例子)
- FLEX例子之弹出提示窗口(Alert)
- 如何设置WebView支持js的Alert,Confirm,Prompt函数的弹出提示框.
- JS不用正则验证输入的字符串是否为空(包含空格)的实现代码
- 一个js验证并提交的例子
- js 正则格式验证与提示
- 客户端基于层的验证不用alert方式
- iOS - 自己定义alertView,继承自UIView,能够加入子视图,标题图片+文字
- 一个简单的验证带验证提示例子
- 客户端基于层的验证不用alert方式
- js 提示警告例子
- jquery.validation.js 表单验证 完整例子使用
- 第一次用javascript写了一个不用刷新就能实现--用户名验证的例子
- 工作中常用到的JS表单验证代码(包括例子)
- js新手学习测试简单例子:十张图片里面选三张图片,超过三张会提示