|
3 | 3 | @Version: 1.3.0 beta
|
4 | 4 | @Author: Ready
|
5 | 5 | @Date: 2015-02-25
|
6 |
| - @Blog: http://www.365mini.com |
| 6 | + @Documentation: http://www.365mini.com/page/jquery-validator-quickstart.htm |
7 | 7 | @Copyright: CodePlayer( Ready )
|
8 | 8 |
|
9 | 9 | @Licence: https://www.apache.org/licenses/LICENSE-2.0.html
|
10 | 10 | */
|
11 | 11 | !function ($, global) {
|
12 | 12 | var console = global && global.console;
|
13 | 13 | if(typeof jQuery === "undefined" || $ !== jQuery){
|
14 |
| - console && console.log("jQuery must be initialied before loading the Validator."); |
| 14 | + console && console.log("jQuery must be initialized before loading the Validator."); |
15 | 15 | return;
|
16 | 16 | };
|
17 | 17 | var V = function(method){
|
|
262 | 262 | }
|
263 | 263 | context.label = label;
|
264 | 264 | }
|
265 |
| - return context.birthday = date; |
| 265 | + return date; |
266 | 266 | }
|
267 | 267 | },
|
268 | 268 | // 校验器
|
|
509 | 509 | },
|
510 | 510 | // 执行单个校验
|
511 | 511 | validate: function(value, rule, event){
|
512 |
| - var me = this, context; |
| 512 | + var me = this, context, is$; |
513 | 513 | if( typeof rule === "string" ){
|
514 | 514 | rule = me.getRule(rule);
|
515 | 515 | if( !rule ) throw "validate rule not found:" + rule;
|
516 | 516 | }
|
517 | 517 | context = V.context = { origin: rule };
|
518 | 518 | rule = context.rule = me.clipRule( rule );
|
519 |
| - V.debug && log( "current validate context:", context ); |
520 |
| - if( value instanceof $ ){ |
| 519 | + is$ = value instanceof $; |
| 520 | + V.debug && log( "current validate context [" + (is$ ? value.prop("name") : value) + "]:" , context ); |
| 521 | + if( is$ ){ |
521 | 522 | if(!value.length && !this.strict) return me.afterHandler(true, context); // 非严格模式,直接跳过校验
|
522 | 523 | context.$dom = value;
|
523 | 524 | value = me.getValue(value, context);
|
|
544 | 545 | if(value == null) context.value = value = ""; // 确保校验器接收到的不会为null或undefined
|
545 | 546 | // 如果设置了非空验证
|
546 | 547 | if( rule.required != null ){
|
547 |
| - context.validator = "required"; |
| 548 | + context.validator = "required", context.expression = rule.required; |
548 | 549 | if( me.validator.required.call(me, value, rule.required, context) === false){
|
549 | 550 | return me.afterHandler(false, context);
|
550 | 551 | }
|
|
553 | 554 | }
|
554 | 555 | // 如果设置了格式验证
|
555 | 556 | if( rule.format ){
|
556 |
| - context.validator = "format"; |
| 557 | + context.validator = "format", context.expression = rule.format; |
557 | 558 | value = me.validator.format.call(me, value, rule.format, context);
|
558 | 559 | if( value === false ) return me.afterHandler(false, context);
|
559 | 560 | if( context._stop ) return me.afterHandler(true, context);
|
|
563 | 564 | for(var i in rule){
|
564 | 565 | var validator = me.validator[i];
|
565 | 566 | if( validator ){
|
566 |
| - context.validator = i; |
| 567 | + context.validator = i, context.expression = rules[i]; |
567 | 568 | if( validator.call(me, value, rule[i], context) === false ){
|
568 | 569 | return me.afterHandler(false, context);
|
569 | 570 | }
|
|
828 | 829 | "username": {
|
829 | 830 | pre: "trimAll,lower,flush",
|
830 | 831 | text: /^[a-z][a-z0-9_]{5,15}$/i,
|
831 |
| - message: "{label}必须是英文、数字和下划线组成的6~16位字符,并且必须以字母开头!" |
| 832 | + message: "{label}必须是英文字母、数字和下划线组成的6~16位字符,并且必须以字母开头!" |
832 | 833 | },
|
833 | 834 | "password": {
|
834 | 835 | length: "[6,16]"
|
|
0 commit comments