Jquery 表单验证
<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.js"
></script>
<script>
$(
function
(){
var
ok1=false;
var
ok2=false;
var
ok3=false;
var
ok4=false;
// 验证用户名
$(
'input[name="username"]'
).focus(
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'
);
}
});
//验证密码
$(
'input[name="password"]'
).focus(
function
(){
$(this).next().text(
'密码应该为6-20位之间'
).removeClass(
'state1'
).addClass(
'state2'
);
}).blur(
function
(){
if
($(this).val().length >= 6 && $(this).val().length <=20 && $(this).val()!=
''
){
$(this).next().text(
'输入成功'
).removeClass(
'state1'
).addClass(
'state4'
);
ok2=true;
}
else
{
$(this).next().text(
'密码应该为6-20位之间'
).removeClass(
'state1'
).addClass(
'state3'
);
}
});
//验证确认密码
$(
'input[name="repass"]'
).focus(
function
(){
$(this).next().text(
'输入的确认密码要和上面的密码一致,规则也要相同'
).removeClass(
'state1'
).addClass(
'state2'
);
}).blur(
function
(){
if
($(this).val().length >= 6 && $(this).val().length <=20 && $(this).val()!=
''
&& $(this).val() == $(
'input[name="password"]'
).val()){
$(this).next().text(
'输入成功'
).removeClass(
'state1'
).addClass(
'state4'
);
ok3=true;
}
else
{
$(this).next().text(
'输入的确认密码要和上面的密码一致,规则也要相同'
).removeClass(
'state1'
).addClass(
'state3'
);
}
});
//验证邮箱
$(
'input[name="email"]'
).focus(
function
(){
$(this).next().text(
'请输入正确的EMAIL格式'
).removeClass(
'state1'
).addClass(
'state2'
);
}).blur(
function
(){
if
($(this).val().search(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/)==-1){
$(this).next().text(
'请输入正确的EMAIL格式'
).removeClass(
'state1'
).addClass(
'state3'
);
}
else
{
$(this).next().text(
'输入成功'
).removeClass(
'state1'
).addClass(
'state4'
);
ok4=true;
}
});
//提交按钮,所有验证通过方可提交
$(
'.submit'
).click(
function
(){
if
(ok1 && ok2 && ok3 && ok4){
$(
'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/>
<a href=
"javascript:;"
><img
class
=
'submit'
type=
'image'
src=
'./images/reg.gif'
/></a>
</form>
</body>
Jquery 表单验证的更多相关文章
- 【jquery】Validform,一款不错的 jquery 表单验证插件
关于 Validform 这是一款很不错的 jquery 表单验证插件,它几乎能够满足任何验证需求,仅仅一行代码就能搞定整站的表单验证. $('form').Validform(); 为什么能如此方便 ...
- 【jQuery基础学习】06 jQuery表单验证插件-Validation
jQuery的基础部分前面都讲完了,那么就看插件了. 关于jQuery表单验证插件-Validation validation特点: 内置验证规则:拥有必填.数字.E-Mail.URL和信用卡号码等1 ...
- python_way day17 jQuery表单验证,事件绑定,插件,文本框架,正则表达式
python_way day17 1.jQuery表单验证 dom事件绑定 jquery事件绑定 $.each return值的判断 jquery扩展方法 2.前段插件 3.jDango文本框架 4. ...
- jquery表单验证使用插件formValidator
JQuery表单验证使用插件formValidator 作者: 字体:[增加 减小] 类型:转载 时间:2012-11-10我要评论 jquery表单验证使用插件formValidator,可供有需求 ...
- jQuery 表单验证插件 jQuery Validation Engine 使用
jQuery 表单验证插件 jQuery Validation Engine 使用方式如下: 1.引入头文件(注意一定要把jQuery放在前面),指定使用 jQuery Validation Engi ...
- jQuery表单验证以及将表单序列化为json对象小练习
jquery表单验证(非实时验证),同时,将表单序列化为json对象提交表单. <!DOCTYPE html> <html lang="en"> <h ...
- JQuery 表单验证--jquery validation
jquery validation,表单验证控件 官方地址 :http://jqueryvalidation.org/ jquery表单验证 默认值校验规则 jquery表单验证 默认的提示 < ...
- jquery validate强大的jquery表单验证插件
jquery validate的官方演示和文档地址: 官方网站:http://jqueryvalidation.org/ 官方演示:http://jqueryvalidation.org/files/ ...
- jQuery框架学习第十一天:实战jQuery表单验证及jQuery自动完成提示插件
jQuery框架学习第一天:开始认识jQueryjQuery框架学习第二天:jQuery中万能的选择器jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQuer ...
- jQuery表单验证案例
目标:使用jQuery进行表单验证. 功能:1.必填选项后面添加了红色小星星: 2.选中开始输入时,输入文本框会改变当前背景色,增强用户体验: 3.输入的时候就开始验证,当输入格式正确就会提醒,就是当 ...
随机推荐
- 关于Linux x64 Oracle JDK7u60 64-bit HotSpot VM 线程栈默认大小问题的整理
JVM线程的栈默认大小,oracle官网有简单描述: In Java SE 6, the default on Sparc is 512k in the 32-bit VM, and 1024k in ...
- font-family 字体
宋体 SimSun黑体 SimHei微软雅黑 Microsoft YaHei微软正黑体 Microsoft JhengHei新宋体 NSimSun新细明体 PMingLiU细明体 MingLiU标楷体 ...
- Android Studio使用org.apache.http报错
Android Studio使用org.apache.http报错需要加上这句话:useLibrary 'org.apache.http.legacy'
- linux 开机自添加路由
进入 vi /etc/sysconfig/network/routes Destination Gateway Genmask Use Iface172. ...
- c语言冒泡排序
在C语言中,常用的排序算法有:冒泡排序.快速排序.插入排序.选择排序.希尔排序.堆排序以及归并排序等等. 冒泡排序基本概念: 依次比较相邻的两个数,将小数放在前面,大数放在后面. #include ...
- SpringMVC对异常进行全局处理,并区分对待ajax和普通请求
异常信息应统一进行处理. 程序员开发过程中,应尽量少用try..catch.避免因为catch造成的业务歧义.而在web开发中,普通的页面提交动作,和ajax提交动作,处理方式不一样,因为跳转后直接显 ...
- git 常见命令
查看.添加.提交.删除.找回,重置修改文件 git help <command> # 显示command的help git show # 显示某次提交的内容 git show $id gi ...
- 老男孩python自动化运维作业2
拿到要求真不知道怎么写,不能还要写个商城页面吧: 最后还是用了input()模拟用户操作吧- -!不就操作个字典吗(字典模拟商品数据). python版本: >>>import sy ...
- 用c和c++的方式实现栈
#include <stdio.h> #include <stdlib.h> #include <assert.h> struct LinkNode { int d ...
- OA及权限系统
一直想找一款适合自己的权限管理后台,始终都没找到合适的,决定自己写一个 开发环境:vs2012 ,sql2008 语言:C# 前端:ligurui,jquery ORM框架:EF6.0 先来晒下我的数 ...