mpassport.js
4.99 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Created by liuziyang on 14-2-25.
*/
var _ruleMobile = /^(((13[0-9]{1})|(18[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
var _ruleEmail = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
jQuery.validator.addMethod("isPhoneOrMail", function (value, element) {
return this.optional(element) || (_ruleEmail.test(value) || _ruleMobile.test(value));
}, "账户必须是邮箱或手机.");
jQuery.validator.addMethod("isPhone", function (value, element) {
return this.optional(element) || _ruleMobile.test(value);
}, "账户必须是手机号码.");
var insertAfterErrorMessages = false;
var signinSetTimeoutID;
function slideUpSetTimeout(){
$('#errorContainer').slideUp();
clearTimeout(signinSetTimeoutID);
}
function signin() {
$("#signinForm").validate({
showErrors: function (errorMap, errorList) {
if (this.numberOfInvalids() == 0) {
$('#errorContainer').slideUp();
}else{
var messages ='';
if(errorMap.profile){
messages = errorMap.profile
}else if(errorMap.password){
messages = errorMap.password
}
if(messages!=''){
$('#errorContainer').slideDown();
$('#errorMessages').text(messages);
}
}
},
success: function (label) {
insertAfterErrorMessages = false;
},
rules: {
profile: {
required: true,
isPhoneOrMail: true
},
password: {
required: true,
minlength: 6,
maxlength: 20
}
},
messages: {
profile: {
required: '邮箱或手机不能为空.',
isPhoneOrMail: '账户必须是邮箱或手机号.'
},
password: {
required: '密码不能为空',
minlength: '密码太短最少6位',
maxlength: '密码太长最多20位'
}
},
onfocusout : false,
onkeyup : false,
onclick : false
});
}
function register() {
$("#registerForm").validate({
showErrors: function (errorMap, errorList) {
if (this.numberOfInvalids() == 0) {
if (_ruleMobile.test($('#profile').val())) {
$('#registerForm').attr('action', '/passport/register/phone');
}
}
if (this.numberOfInvalids() == 0) {
$('#errorContainer').slideUp();
}else{
var messages ='';
if(errorMap.profile){
messages = errorMap.profile
}else if(errorMap.password){
messages = errorMap.password
}else if(errorMap.confirm_password){
messages = errorMap.confirm_password
}
if(messages!=''){
$('#errorContainer').slideDown();
$('#errorMessages').text(messages);
}
}
},
success: function (label) {
insertAfterErrorMessages = false;
},
rules: {
profile: {
required: true,
isPhone: true
},
password: {
required: true,
minlength: 6,
maxlength: 20
},
confirm_password: {
required: true,
equalTo: '#password'
}
},
messages: {
profile: {
required: '手机号码不能为空.',
isPhone: '账户必须是手机号.'
},
password: {
required: '密码不能为空',
minlength: '密码太短最少6位.',
maxlength: '密码太长最多20位'
},
confirm_password: {
required: '确认密码不能为空',
equalTo: '确认密码和输入密码不相同.'
}
},
onfocusout : false,
onkeyup : false,
onclick : false
});
}