jQuery validator plugin之Methods
Makes the element require a given step.
step( value )
- valueType: NumberStep value required
normalizer
Prepares/transforms the elements value for validation.
normalizer( value )
- valueType: StringThe value of the element.
Transform the value of an element and the result for validation instead of the initial value.
The normalizer can be defined global to all elements or local to only one element.
- With that said, the local normalizer will only run for the element for which it was defined.
- The global normalizer will run for all validated elements.
This normalizer can be then overrided for each element, as needed, by attaching one to it.
This way only the local one will run for that element, and the global one will run for others.
Note that this method:
- Doesn't change the elements' value, it only changes the value used for validation.
- Gets the value passed as argument, and "this" within it references the corresponding
DOMElement
. - Needs to return a String value, otherwise it will throw a
TypeError
exception.
require_from_group method
Ensures a given number of fields in a group are complete.
In the options passed to the rule, supply the minimum number of fields
within the group that must be complete and a selector to define the
group.
Then apply this rule to all the fields within the group.
The form then cannot be submitted until at least the minimum number have
been completed.
Part of the additional-methods.js file
url method
Makes the element require a valid url
Return true, if the value is a valid url.
Works with text inputs.
required method
Makes the element required.
required()
required( dependency-expression )
- dependency-expressionType: StringAn expression (String) that is evaluated in the context of the element's
form, making the field required only if the expression returns more
than one element.- Very often your expression will use selector filters such as
#foo:checked
,#foo:filled
,#foo:visible
. This plugin provides custom selectors for that purpose.
- Very often your expression will use selector filters such as
required( dependency-callback )
- dependency-callbackType: Function()The function is executed with the element as it's only argument: If it returns true, the element is required.
- Return false, if the element is empty (text input) or unchecked (radio/checkbox) or if nothing is selected (select).
- Works with text inputs, selects, checkboxes and radio buttons.
- To force a user to select an option from a select box, provide an empty
option element like <option value="">Choose…</option> - Note that white spaces are considered valid.
remote method
remote( options )
- Requests a resource to check the element for validity.
- optionsType: ObjectFor the URL of the resource to request for serverside validation (String) or options to fully customize the request, see jQuery.ajax for details.
- These options deep-extend the defaults (
dataType:"json", data:{nameOfTheElement:valueOfTheElement}
). Any options you provide will override the defaults.
- These options deep-extend the defaults (
- The serverside resource is called via jQuery.ajax (XMLHttpRequest) and
gets a key/value pair corresponding to the name of the validated element
and its value as a GET parameter.- The serverside response must be a
JSON string that must be"true"
for valid elements, and can be"false"
,undefined
, ornull
for invalid elements, using the default error message. - If the serverside response is a string, eg.
"That name is already taken, try peter123 instead"
, this string will be displayed as a custom error message in place of the default. - For more examples, take a look the marketo demo and the milk demo.
- The serverside response must be a
rangelength method
rangelength( range )
- rangeType: ArrayValue range required
Return false if the element is:
- some kind of text input and its length is too short or too long
- a set of checkboxes that doesn't have enough, or has too many boxes checked
- a select that doesn't have enough, or has too many options selected
Works with text inputs, selects and checkboxes.
range method
range( range )
- rangeType: ArrayValue range required
phoneUS method
Validate for valid US phone number.
Works with text inputs.
Part of the additional-methods.js file
number method
Makes the element require a decimal number.
Returns true if the value contains a valid decimal number.
Works with text inputs.
- valueType: NumberStep value required
jQuery validator plugin之Methods的更多相关文章
- jQuery validator plugin 之 custom methods 案例1:multi email
1.add method jQuery.validator.addMethod( "multiemail", function (value, element) { var ema ...
- jQuery validator plugin之概要
jQuery validator 主页 github地址 demo学习 效果: Validate forms like you've never validated before! 自定义Valida ...
- jQuery validator plugin之Validator
Validator.destroy() Destroys this instance of validator freeing up resources and unregistering event ...
- jQuery validator plugin之Plugin Method
原文 .validate() validate( [options ] ) options Type: Object debug (default: false) Type: Boolean Enab ...
- jQuery validator plugin之Selector
原文 :unchecked Selector Selects all elements that are unchecked. jQuery( ":unchecked" ) Inv ...
- jQuery.validator 详解二
前言:上一篇详细的介绍了jQuery.validator( 版本v1.13.0 )的验证规则,这一篇重点讲述它的源码结构,及如何来对元素进行验证,错误消息提示的内部实现 一.插件结构(组织方式) 在讲 ...
- jQuery.validator 详解
jQuery.validator 详解二 前言:上一篇详细的介绍了jQuery.validator( 版本v1.13.0 )的验证规则,这一篇重点讲述它的源码结构,及如何来对元素进行验证,错误消息提示 ...
- jQuery Validation Plugin学习
http://blog.csdn.net/violet_day/article/details/14109261 jQuery Validation Plugin Demo 一.默认校验规则 (1)r ...
- (转)jquery.validator规则
登录|注册 收藏成功 确定 收藏失败,请重新收藏 确定 标题 标题不能为空 网址 标签 摘要 公开 取消收藏 分享资讯 传PPT/文档 提问题 写博客 传资源 ...
随机推荐
- 查看oracle数据库是否为归档模式
查看oracle数据库是否为归档模式 [1] 1.select name,log_mode from v$database; NAME LOG_MODE --------------- ...
- CF3A Shortest path of the king
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...
- 测量应用程序cass和cad的使用感受
作为一名测绘工程专业的学生,在现在的电子信息时代是会经常与测量绘图有关的软件打交道的,如今我也算是接触绘图软件一年多了并且在上学期学校还组织我们大家一起进行了几周CAD集训,而且在校园和井陉的暑期实训 ...
- Codeforces 706C - Hard problem - [DP]
题目链接:https://codeforces.com/problemset/problem/706/C 题意: 给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整 ...
- MySQL 连接数相关参数设置
当我们的数据库服务器遇到如下的错误:ERROR: Too many connections 一种可能性就是我们的压力确实很大,需要增加服务器硬件资源或者增加数据库服务器.但是大多数情况下是我们的连接数 ...
- Codeforces Round div2 #541 题解
codeforces Round #541 abstract: I构造题可能代码简单证明很难 II拓扑排序 III并查集 启发式排序,带链表 IV dp 处理字符串递推问题 V 数据结构巧用:于二叉树 ...
- day16:内置函数二
1,大作业,yield 返回之后可以对数据进行处理了就,注意函数的解耦,每一个小功能写成一个函数,增强可读性,写之前自己要先把整体功能分块,先做什么,在做什么 # 现在需要对这个员工信息文件进行增删改 ...
- CORS jsonp
现在碰到了请求跨域的问题,结合前面讲的一些概念,我们大致可以猜到解决跨域请求的两种方式: 在服务端启用CORS.让无服务端拥有处理JSONP的能力.这两种跨域解决方案的区别是什么呢? JSONP只支持 ...
- [efficiency] emacs入门
一. 没记错的话,这可能是第三次读emacs tutorial了.前两次读的非常慢,也不记得有没有读完了.总之最后都忘光了. 这次读的很顺畅,利用工作的空闲时间加上今天晚上(周日).总算是读完了. 没 ...
- P5280 [ZJOI2019]线段树
题目链接:洛谷 题目描述:[比较复杂,建议看原题] 这道题太神仙了,线段树上做树形dp. 根据树形dp的套路,都是按照转移的不同情况给节点分类.这里每次modify的时候对于节点的影响也不同,所以我们 ...