1 equalTo: function( value, element, param ) {
2
3 // Bind to the blur event of the target in order to revalidate whenever the target field is updated
4 var target = $( param );
5 if ( this.settings.onfocusout && target.not( ".validate-equalTo-blur" ).length ) {
6 target.addClass( "validate-equalTo-blur" ).on( "blur.validate-equalTo", function() {
7 $( element ).valid();
8 } );
9 }
10 return value === target.val();
11 },
url验证方法:
1 url: function( value, element ) {
2
3 // Copyright (c) 2010-2013 Diego Perini, MIT licensed
4 // https://gist.github.com/dperini/729294
5 // see also https://mathiasbynens.be/demo/url-regex
6 // modified to allow protocol-relative URLs
7 return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value );
8 },
日期date验证方法:
1 // http://jqueryvalidation.org/date-method/
2 date: function( value, element ) {
3 return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
4 },
十进制数字含小数验证方法:
1 // http://jqueryvalidation.org/number-method/
2 number: function( value, element ) {
3 return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
4 },
整数验证方法:
1 // http://jqueryvalidation.org/digits-method/
2 digits: function( value, element ) {
3 return this.optional( element ) || /^\d+$/.test( value );
4 },
最小长度验证方法:
1 // http://jqueryvalidation.org/minlength-method/
2 minlength: function( value, element, param ) {
3 var length = $.isArray( value ) ? value.length : this.getLength( value, element );
4 return this.optional( element ) || length >= param;
5 },
最大长度验证方法:
1 // http://jqueryvalidation.org/maxlength-method/
2 maxlength: function( value, element, param ) {
3 var length = $.isArray( value ) ? value.length : this.getLength( value, element );
4 return this.optional( element ) || length <= param;
5 },
1 messages: {
2 required: "This field is required.",
3 remote: "Please fix this field.",
4 email: "Please enter a valid email address.",
5 url: "Please enter a valid URL.",
6 date: "Please enter a valid date.",
7 dateISO: "Please enter a valid date ( ISO ).",
8 number: "Please enter a valid number.",
9 digits: "Please enter only digits.",
10 equalTo: "Please enter the same value again.",
11 maxlength: $.validator.format( "Please enter no more than {0} characters." ),
12 minlength: $.validator.format( "Please enter at least {0} characters." ),
13 rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ),
14 range: $.validator.format( "Please enter a value between {0} and {1}." ),
15 max: $.validator.format( "Please enter a value less than or equal to {0}." ),
16 min: $.validator.format( "Please enter a value greater than or equal to {0}." ),
17 step: $.validator.format( "Please enter a multiple of {0}." )
18 },