jQuery Validate插件实现表单强大的验证功能
转自:http://www.jb51.net/article/76595.htm
jQuery Validate插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来编写用户自定义方法的 API。所有的捆绑方法默认使用英语作为错误信息,且已翻译成其他 37 种语言。
第一节:jQuery Validation让验证变得如此容易
一、官网下载jquery,和jquery validation plugin
二、引入文件
<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script> <script src="js/jquery.validate.js" type="text/javascript"></script><form action="" id="jvForm"> 姓名:<input type="text" name="username" id="username" class="required" /></br> 密码:<input type="password" name="password" id="password" class="required"/></br> <input type="submit" value="提交" /> </form> 他的作用就是在这个inpute标签为空时会提示用户出错。
<script type="text/javascript"> $(function() { $("#jvForm").validate(); }) </script> 
第二节:jQuery Validation让验证变得如此容易
上一个例子我们是统一引用jquery.validate.js这样所有必填字段的提示信息都将是This field is required.
现在要改成动态提示,比如姓名如果为空则提示姓名不能为空,密码如果为空则提示密码不能为空。
这次我们将校验规则写在代码里
首先还是先引入文件
<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script> <script src="js/jquery.validate.js" type="text/javascript"></script> <form action="" id="jvForm"> 姓名:<input type="text" name="username" id="username" /></br> 密码:<input type="password" name="password" id="password" /></br> <input type="submit" value="提交" /> </form> 最后 校验规则如下:
$(function() { $("#jvForm").validate({ rules: { username: { required: true }, password: { required: true } }, messages: { username: { required: "姓名不能为空!" }, password: { required: "密码不能为空!" } } }); }) 
第三节:jQuery Validation让验证变得如此容易
以下代码进行对jQuery Validation的简单演示包括必填项、字符长度,格式验证
一、引入文件
<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script> <script src="js/jquery.validate.js" type="text/javascript"></script><form action="" id="jvForm"> 用 户 名:<input type="text" name="username"/></br> 密 码:<input type="password" name="password" id="password"/></br> 确认密码:<input type="password" name="confirm_password"/></br> 出 生 地:<select name="address"><option value="">--</option><option value="1">北京</option> <option value="1">上海</option><option value="1">深圳</option></select></br> 手 机:<input type="text" name="mobile" /></br> 邮 箱:<input type="text" name="email" /></br> <input type="submit" value="提交" /> </form> <style type="text/css"> label.error{font-size:12px;font-weight: normal;color:#ff0511;margin-left:10px;} </style><script type = "text/javascript"> $(function() { $("#jvForm").validate({ rules: { username: { //用户名必填 至少3位 required: true, minlength: 3 }, password: { //密码必填 至少6位 required: true, minlength: 6 }, confirm_password: { //密码确认 required: true, equalTo: "#password" }, address: { //出生地必填 required: true }, mobile: { //手机必填 验证格式 required: true, mobile: true }, email: { //email必填 验证格式 required: true, email: true }, }, messages: { username: { required: "用户名不能为空!", minlength: "用户名至少三位!" }, password: { required: "密码不能为空!", minlength: "密码至少六位!" }, confirm_password: { required: "密码确认不能为空!", equalTo: "两次输入密码不一致 !" }, address: { required: "请选择出生地!", }, mobile: { required: "手机不能为空!", mobile: "手机格式不正确", }, email: { required: "邮箱不能为空!", email: "邮箱格式不正确", }, } }); }) </script>
jQuery Validate插件实现表单强大的验证功能的更多相关文章
- jQuery Validate 插件为表单提供了强大的验证功能
之前项目开发中,表单校验用的jQuery Validate 插件,这个插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的 ...
- validate插件实现表单效验(二)
一款优秀的表单验证插件——validation插件 特点: l 内置验证规则:拥有必填.数字.email.url和信用卡号码等19类内置验证规则 l 自定义验证规则:可以很方便的自定义验证规则 l ...
- jquery validate 一个注册表单的应用
先看页面 前端表单代码 register.html <form class="mui-input-group" id="regForm"> < ...
- 表单提交学习笔记(二)—使用jquery.validate.js进行表单验证
一.官网下载地址:http://plugins.jquery.com/validate/ 二.用法 1.在页面上进行引用 <script src="~/scripts/jquery-1 ...
- jquery.validate.js自定义表单验证
$(document).ready(function() { //在下列位置输入页面加载的逻辑代码 $("#inputForm").validate({ rules: { seq: ...
- validate插件实现表单效验(一)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- [转]jQuery.validate插件在失去焦点时执行验证代码
转:http://my.oschina.net/enyo/blog/311566 关于 jquery.validate.js 表单验证插件如何在失去焦点时做验证.看手册后发现默认是在表单提交时执行验证 ...
- jQuery html5Validate基于HTML5表单 异步服务器端验证
1. HTML5 自带的Validate 很漂亮,很好用, 但是一定要在form里用submit按钮,才生效 <form id="frmInfo" action=" ...
- jquery.form插件 提交表单 type="hidden"取不到值的问题记录
1.外国文献:说可以改成其他的(非hidden),再加style="display:none"隐藏. <INPUT type="password" sty ...
随机推荐
- (转)MySQL中的索引详讲
序言 之前写到MySQL对表的增删改查(查询最为重要)后,就感觉MySQL就差不多学完了,没有想继续学下去的心态了,原因可能是由于别人的影响,觉得对于MySQL来说,知道了一些复杂的查询,就够了,但是 ...
- axios在vue项目中的一种封装方法
记录下之前领导封装的axios请求 npm install axios // 安装 单独写个文件配置axios,此处为request.js import axios from 'axios' //自定 ...
- 可以通过dict[key]获得dict[value]
dict={key:value,key2:value2} print (dict[key] ) 得到的是 dict[value] # 软文预存接口,通过key来预览未保存的软文,联查商品.kol ...
- PyQt5Icon图标(Icon)无法显示问题
PyQt5中设置图标无法显示 以下源码来源PyQt5教程http://zetcode.com/gui/pyqt5/firstprograms/ import sys from PyQt5.QtWidg ...
- Shiro_认证思路分析
[认证] 也就是登录. 1.获取当前的subject,调用SecurityUtils.getSubject() 2.测试当前的用户是否已经被认证,即是否登录.调用subject的isAuthentic ...
- opengl 对投影变化函数的理解
投影变化分两种: 1 . 平行投影 2 . 透视投影 投影变化的设置一般放在reshape函数当中调用 每次要对投影变化进行操作的时候我们需要修改矩阵的变化模式,指定它为投影变化 glMa ...
- [luoguP2758] 编辑距离(DP)
传送门 f[i][j] 表示第一串前 i 个到第二串前 j 个的最小编辑距离 f[i][j] = f[i - 1][j - 1] (s1[i] == s2[j]) f[i][j] = min(f[i ...
- [K/3Cloud]调用动态表单时,传递自定义参数
插件中在调用动态表单时,通过DynamicFormShowParameter的CustomParams,增加自定义的参数. private void ShowMaterialStock() { obj ...
- Codeforces Round #403(div 2)
A =w= B 题意:一个数轴上有n个整点,每个点都有一个速度,选一个点让他们集合,使得时间最少. 分析: 直接三分 C 题意:给定一棵树,任意两个距离小等于二的点不能染相同的颜色,求最小颜色数和染色 ...
- Mutual Training for Wannafly Union #5
A(UVA12336) 题意:给一个n*m(n,m<=1e5)的棋盘,棋盘上有一些障碍点不能放棋子,现在要在棋盘上放4个棋子,满足A->B->C->D->A,其中走的规则 ...