-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution-jQuery.js
More file actions
executable file
·205 lines (195 loc) · 6.34 KB
/
Copy pathsolution-jQuery.js
File metadata and controls
executable file
·205 lines (195 loc) · 6.34 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*jslint plusplus: true, sloppy: true, browser: true, devel: true */
/*global jQuery, $*/
var spellcheck = function (data) {
var i, found = false, url = '', text = data[0];
if (text !== document.getElementById('occupation').value) {return; }
for (i = 0; i < data[1].length; i++) {
if (text.toLowerCase() === data[1][i].toLowerCase()) {
found = true;
url = 'http://en.wikipedia.org/wiki/' + text;
document.getElementById('spellcheckresult').innerHTML = '<b style="color:green;">Correct</b> - <a target="_top" href="' + url + '">link</a>';
}
}
if (!found) { document.getElementById('spellcheckresult').innerHTML = '<b style="color:red;">Incorrect</b>'; }
};
var getjs = function (value) {
if (!value) {return; }
var url, elem;
url = 'http://en.wikipedia.org/w/api.php?action=opensearch&search=' + value + '&format=json&callback=spellcheck';
document.getElementById('spellcheckresult').innerHTML = 'Checking ...';
elem = document.createElement('script');
elem.setAttribute('src', url);
elem.setAttribute('type', 'text/javascript');
document.getElementsByTagName('head')[0].appendChild(elem);
};
$.validator.addMethod(
"dateFormat",
function (value) {
var isValidated = value.match(/^(0?[1-9]|[12][0-9]|3[01])[\-](0?[1-9]|1[012])[\-]\d{4}$/);
if (isValidated) {
$("#bdaylabel").css("color", "#666666");
} else {
$("#bdaylabel").css("color", "red");
}
return isValidated;
},
"Please enter a date in the format DD-MM-YYYY"
);
$.validator.addMethod(
"fnameRequired",
function (value) {
var error = false;
if (value.length === 0 || value === null || value === "") {
$("#fnamelabel").css("color", "red");
error = false;
} else {
$("#fnamelabel").css("color", "#666666");
error = true;
}
return error;
},
"Please enter the First Name"
);
$.validator.addMethod(
"fnameFormat",
function (value) {
var isValidated = value.match(/^[A-Za-z]+$/);
if (isValidated) {
$("#fnamelabel").css("color", "#666666");
} else {
$("#fnamelabel").css("color", "red");
}
return isValidated;
},
"First Name can contain only characters a-z and A-Z"
);
$.validator.addMethod(
"lnameRequired",
function (value) {
var error = false;
if (value.length === 0 || value === null || value === "") {
$("#lnamelabel").css("color", "red");
error = false;
} else {
$("#lnamelabel").css("color", "#666666");
error = true;
}
return error;
},
"Please enter the Last Name"
);
$.validator.addMethod(
"lnameFormat",
function (value) {
var isValidated = value.match(/^[A-Za-z]+$/);
if (isValidated) {
$("#lnamelabel").css("color", "#666666");
} else {
$("#lnamelabel").css("color", "red");
}
return isValidated;
},
"Last Name can contain only characters a-z and A-Z"
);
$.validator.addMethod(
"mnameFormat",
function (value) {
var isFormatted = false, isValidated = value.match(/^[A-Za-z]+$/);
if (!(value.length === 0 || value === null || value === "")) {
if (isValidated) {
$("#mnamelabel").css("color", "#666666");
} else {
$("#mnamelabel").css("color", "red");
}
isFormatted = isValidated;
} else {
$("#mnamelabel").css("color", "#666666");
isFormatted = true;
}
return isFormatted;
},
"Middle Name can contain only characters a-z and A-Z"
);
$.validator.addMethod(
"emailRequired",
function (value) {
var isFormatted = false;
if (value.length === 0 || value === null || value === "") {
$("#emaillabel").css("color", "red");
isFormatted = false;
} else {
$("#emaillabel").css("color", "#666666");
isFormatted = true;
}
return isFormatted;
},
"Please enter Email"
);
$.validator.addMethod(
"bdayRequired",
function (value) {
var isFormatted = false;
if (value.length === 0 || value === null || value === "") {
$("#bdaylabel").css("color", "red");
isFormatted = false;
} else {
$("#bdaylabel").css("color", "#666666");
isFormatted = true;
}
return isFormatted;
},
"Please enter Birthday"
);
$(document).ready(function () {
$("#userForm").validate({
rules: {
onsubmit: true,
fname: {
fnameRequired : true,
fnameFormat: true
},
lname: {
lnameRequired : true,
lnameFormat: true
},
mname: {
mnameFormat: true
},
email: {
emailRequired : true,
email : true
},
bday: {
dateFormat : true,
bdayRequired : true
},
'gender': {
required: true
}
},
messages: {
fname: {
fnameRequired: "Please enter the First Name",
fnameFormat: "First Name can contain only characters a-z and A-Z"
},
lname: {
lnameRequired: "Please enter the Last Name",
lnameFormat: "Last Name can contain only characters a-z and A-Z"
},
mname: {
mnameFormat: "Middle Name can contain only characters a-z and A-Z"
},
email: {
emailRequired: "Please enter Email",
email: "Email must correspond to the pattern name@domain.com"
},
bday: {
bdayRequired: "Please enter Birthday",
dateFormat: "Please enter a date in the format DD-MM-YYYY"
},
'gender': {
required: "Please select Gender"
}
}
});
});