-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
171 lines (150 loc) · 4.52 KB
/
index.js
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"use strict"
$(function () {
// user name tooltip
new jBox("Tooltip", {
attach: "#username",
theme: "TooltipBorderThick",
width: '500px',
height: '50px',
position: {
x: "left",
y: "center",
},
outside: "x",
pointer: "top:15",
content: "<div style='color: green;'>You can use letters, dots and underscore</div>",
animation: "move",
});
// password tooltip
new jBox("Tooltip", {
attach: "#password",
theme: "TooltipBorderThick",
width: '400px',
height: '60px',
position: {
x: "left",
y: "center",
},
outside: "x",
pointer: "top:15",
content: "<div style='color: green;'>Use at least 8 characters. Don't use password from another site, or something to obvious</div>",
animation: "move",
});
// dropdowns
$("#month").select2({
placeholder: {
id: "-1",
text: "Select an option",
},
});
$("#gender").select2({
placeholder: {
id: "-1",
text: "Select an option",
},
});
// clear error label id data selected
$('#month').on('select2:select', function (e) {
$('#month-error').text('');
});
$('#gender').on('select2:select', function (e) {
$('#gender-error').text('');
});
// check box
$("#agree").iCheck({
checkboxClass: "icheckbox_square-blue",
radioClass: "iradio_square-blue",
increaseArea: "20%", // optional
});
// disable or enable submit
$('#agree').on('ifChecked', (event) => {
$('#submit').prop('disabled', false);
});
$('#agree').on('ifUnchecked', (event) => {
$('#submit').prop('disabled', true);
});
// custom validation methods
$.validator.addMethod("username", function (value, element) {
return this.optional(element) || value == value.match(/^[a-zA-Z._]+$/);
}, "a-z, A-Z, ' . ' and ' _ ' only please");
$.validator.addMethod("confirm_password", function (value, element) {
return this.optional(element) || value === $('#password').val();
}, "password does not match");
// validate from
$('#from').validate({
// rule for every inout
rules: {
fname: "required",
lname: "required",
username: {
required: true,
username: true,
},
password: {
required: true,
minlength: 8,
},
c_password: {
required: true,
confirm_password: true
},
month: "required",
day: {
required: true,
number: true,
min: 1,
max: 31
},
year: {
required: true,
number: true,
min: 1800,
max: 2020
},
gender: "required",
agree: "required",
},
errorPlacement: function (error, element) {
error.appendTo(`#${element.attr("name")}-error`);
},
errorClass: "error fail-alert",
validClass: "valid success-alert",
// error messages
messages: {
fname: {
required: "First name is required<br>"
},
lname: {
required: "Last name is required"
},
username: {
required: "Username can't leave empty"
},
password: {
required: "Please Enter a password",
minlength: "password must be at least 8 characters"
},
c_password: {
required: "Please confirm your password",
},
month: {
required: "Select you birthday month<br>",
},
day: {
required: "Day is required<br>",
number: "Day must be integer<br>",
min: "Day must be upper than 1<br>",
max: "Day must be lower than 31<br>"
},
year: {
required: "Year is required<br>",
number: "Year must be integer<br>",
min: "Year must be upper than 1800<br>",
max: "Year must be lower than 2020<br>"
},
gender: {
required: "Please select your Gender"
}
},
});
});