demo.js
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
jQuery.validator.addMethod("isLock", function(value, element) {
var lock = /[A-Z]/;
return this.optional(element) || (!lock.test(value));
}, "Email不能有大写字母");
function validateRight(str, id){
$("#"+id+"_dl").attr('class','tips-box-error');
$("#c_"+id).hide('fast');
return '<span class="tips-error">'+str+'</span>';
}
$(document).ready(function(){
$('input').focus(function(){
var cls = $('#'+this.id).attr('class');
if(cls != 'input_1 error'){
$("#"+this.id+"_dl").attr('class','tips-box-text');
}
});
$('input').blur(function() {
var cls = $('#'+this.id).attr('class');
if(cls != 'input_1 error'){
$("#"+this.id+"_dl").removeClass();
}
});
});
$().ready(function() {
$("#registerForm").validate({
debug:true,
// onclick:false,
// onkeyup:false,
// focusInvalid:false,
// onkeyup:false,
// errorElement : "span",
// errorClass:"tips-error",
rules : {
email : {
required : true,
minlength : 6,
email : true,
isLock : true
// remote : "/passport/reg/authmail"
},
password : {
required : true,
minlength : 6,
maxlength : 30
},
confirm_password : {
required : true,
minlength : 6,
equalTo : "#password"
},
auth_code : {
required : true,
// remote : "/passport/images/verifyimgcode",
minlength : 4,
maxlength : 4
}
},
messages : {
email : {
required : function(val, obj){
return validateRight( "此邮箱将作为您的登录邮箱!" ,obj.id);
},
minlength : function(val, obj){
return validateRight( "Email地址太短,最少6位!" ,obj.id);
},
email : function(val, obj){
return validateRight("请填写正确的格式" ,obj.id);
},
// remote : "已经被注册或错误的Email!"
},
password : {
required : "请输入密码!",
minlength : jQuery.format("你的密码太短,最少{0}位!"),
maxlength : jQuery.format("密码最长{0}位")
},
confirm_password : {
required : "请输入确认密码!",
minlength : "确认密码太短!",
equalTo : "确认密码不正确,请重新输入."
},
auth_code : {
required : '请输入验证码.',
// remote : "验证码错误.",
minlength : jQuery.format("验证码{0}位."),
maxlength : jQuery.format("验证码{0}位.")
}
},
success:function(label){
var htmlfor = label.attr('for');
var cls = $('#'+htmlfor).attr('class');
if(cls != 'input_1 valid'){
$("#c_"+htmlfor).show('fast',function(){
$("#"+htmlfor+"_dl").attr('class','tips-box-text');
$("#c_"+htmlfor).attr('class','tips-right');
});
// label.after('<span id="'+htmlfor+'_right"
// class="tips-right">正确提示</span>');
}
}
});
});