form表单验证(非原创)
2015-05-15 17:53
351 查看
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Reg</title>
<style>
.state1{
color:#aaa;
}
.state2{
color:#000;
}
.state3{
color:red;
}
.state4{
color:green;
}
</style>
<script src="jquery-1.10.2.min.js" type="text/javascript"></script>
<script>
$(function(){
$('input[name="username"]').keypress(function(){
$(this).next().text('用户名应该为3-20位之间').removeClass('state1').addClass('state2');
}).blur(function(){
if($(this).val().length >= 3 && $(this).val().length <=12 && $(this).val()!=''){
$(this).next().text('输入成功').removeClass('state1').addClass('state4');
ok1=true;
}else{
$(this).next().text('用户名应该为3-20位之间').removeClass('state1').addClass('state3');
}
});
function checkForm(){
var $usersName = $('input[name="username"]');
if($usersName.val().length >= 6 && $usersName.val().length <=20 &&$usersName.val()!=''){
$usersName.next().text('输入成功').removeClass('state1').addClass('state4');
return true;
}else{
$usersName.next().text('密码应该为6-20位之间').removeClass('state1').addClass('state3');
return false;
}
}
//提交按钮,所有验证通过方可提交
$('.submit').click(function(){
if(checkForm()){
$('form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<form action='do.php' method='post' >
用 户 名:<input type="text" name="username">
<span class='state1'>请输入用户名</span><br/><br/>
密 码:<input type="password" name="password">
<span class='state1'>请输入密码</span><br/><br/>
确认密码:<input type="password" name="repass">
<span class='state1'>请输入确认密码</span><br/><br/>
邮 箱:<input type="text" name="email">
<span class='state1'>请输入邮箱</span><br/><br/>
<input type="button" value="提交" id="toSubmitId"/>
<a href="javascript:;"><img id="" class='submit' type='image' src='./images/reg.gif' /></a>
</form>
</body>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Reg</title>
<style>
.state1{
color:#aaa;
}
.state2{
color:#000;
}
.state3{
color:red;
}
.state4{
color:green;
}
</style>
<script src="jquery-1.10.2.min.js" type="text/javascript"></script>
<script>
$(function(){
$('input[name="username"]').keypress(function(){
$(this).next().text('用户名应该为3-20位之间').removeClass('state1').addClass('state2');
}).blur(function(){
if($(this).val().length >= 3 && $(this).val().length <=12 && $(this).val()!=''){
$(this).next().text('输入成功').removeClass('state1').addClass('state4');
ok1=true;
}else{
$(this).next().text('用户名应该为3-20位之间').removeClass('state1').addClass('state3');
}
});
function checkForm(){
var $usersName = $('input[name="username"]');
if($usersName.val().length >= 6 && $usersName.val().length <=20 &&$usersName.val()!=''){
$usersName.next().text('输入成功').removeClass('state1').addClass('state4');
return true;
}else{
$usersName.next().text('密码应该为6-20位之间').removeClass('state1').addClass('state3');
return false;
}
}
//提交按钮,所有验证通过方可提交
$('.submit').click(function(){
if(checkForm()){
$('form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<form action='do.php' method='post' >
用 户 名:<input type="text" name="username">
<span class='state1'>请输入用户名</span><br/><br/>
密 码:<input type="password" name="password">
<span class='state1'>请输入密码</span><br/><br/>
确认密码:<input type="password" name="repass">
<span class='state1'>请输入确认密码</span><br/><br/>
邮 箱:<input type="text" name="email">
<span class='state1'>请输入邮箱</span><br/><br/>
<input type="button" value="提交" id="toSubmitId"/>
<a href="javascript:;"><img id="" class='submit' type='image' src='./images/reg.gif' /></a>
</form>
</body>
相关文章推荐
- Extjs form validate 表单验证总结
- 异步提交form的时候利用jQuery validate实现表单验证
- 基于Bootstrap+jQuery.validate实现Form表单验证
- ASP.NET在IE9,IE10,IE11中Form表单身份验证失效问题解决方法
- 扩展CodeIgniter的表单验证(Form_validatioin)类和解决Model类调用callback_的问题
- JQuery 和JS 对Form表单验证和输入框验证
- 利用Jquery实现一个典型的form表单前端验证
- yii 使用cactiveform 创建表单时候遇到的一些验证问题和使用ajax_form时重置验证规则的解决办法
- form的onsubmit事件--表单提交前的验证最佳实现方式
- 一个写的挺干净的form表单验证,简洁
- asp.net利用js进行form验证表单
- 异步提交form的时候利用jQuery validate实现表单验证
- Form表单利用jQuery Validate验证ajaxSubmit提交
- 手机号验证,为jquery-validation添加自定义验证方式,以及Ajax提交form表单
- Vue Element Form表单时间验证控件使用
- [转摘]jQuery formValidator表单验证插件开源了!!含API帮助、源码、示例
- form 表单验证提交
- Easyui Ajax验证Form表单。。。
- JS formvalidator 表单验证试用
- form的onsubmit事件--表单提交前的验证最佳实现方式