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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
jQuery.validator.addMethod("lettersonly", function(value, element) { 
	return this.optional(element) || /^[a-z\s]*$/i.test(value);
}, jQuery.format("Please enter only letters")); 

jQuery.validator.addMethod("zip", function(value, element) { 
	return this.optional(element) || /^\d{5}$|^\d{5}\-\d{4}$/i.test(value);
}, jQuery.format("Please enter your zip correctly: (e.g. 99999 or 99999-9999)"));

jQuery.validator.addMethod("reg_code", function(value, element) { 
	return this.optional(element) || /^TexasTech$|^Aggie$|^2013$|^UTMB$|^ETX$|^UTD$|^UTT$|^PO$|^ONE$/i.test(value);
}, jQuery.format("Please enter a valid registration code")); 

jQuery.validator.addMethod("passw", function(value, element) { 
	return this.optional(element) || /^(?=.*[\W])(?=.*[\d])(?=.*[A-Z]).{8,}$/.test(value);
}, jQuery.format("Please enter a valid password"));  
	
var val = $('#everything').validate({
	onkeyup: false,
	errorClass: "req_mess",
	ignore: ":hidden",
	rules: {
		fname: {
			required: true,
			minlength: 1,
			lettersonly: true
		},
		lname: {
			required: true,
			minlength: 1,
			lettersonly: true
		},
		address: {
			required: true,
			minlength: 1
		},
		city: {
			required: true,
			minlength: 1,
			lettersonly: true	
		},
		state: {
			required: {
				depends: function(iitype) {
					return $("#state").val() == "";
				}
			}
		},
		zip: {
			required: true,
			minlength: 5,
			zip: true
		},
		phone: {
			required: true,
			minlength: 10,
			phoneUS: true
		},
		email: {
			required: true,
			email: true,
			remote: { url: "Private/Email_checker.php", async: false }
		},
		ver_email: {
			equalTo: "#email"
		},
		institution: {
			required: true
		},
		type: {
			required: true
		},
		address_sch: {
			required: true
		},
		prize_name: {
			required: "#prize:visible"
		},
		descr: {
			required: "#prize:visible"
		},
		retail: {
			required: "#prize:visible",
			digits: true
		},
		iitype: {
			required: {
				depends: function(iitype) {
					return $("#iitype").val() == "";
				}
			}
		},
		type: {
			required: {
				depends: function(type) {
					return $("#type").val() == "";
				}
			}
		},
		iitdescr: {
			required: "#otherdescr1:visible"
		},
		typedescr: {
			required: "#otherdescr2:visible"
		},
		city_sch: {
			lettersonly: true
		},
		state_sch: {
			lettersonly: true
		},
		zip_sch: {
			zip: true
		},
		username: {
			required: true,
			remote: { url: "Private/Available.php", async: false }
		},
		password: {
			required: true,
			passw: true
		},
		password_verify: {
			required: true,
			equalTo: "#password"
		},
		regis_code: {
			required: true,
			reg_code: true,
			remote: { 
				url: "Private/Code_checker.php", 
				data: {
					code: function() {
					   return $("#regis_code").val();
					}
				},
				async: false 
			}
		}
	},
	messages: {
		fname: {
			required: "Please enter your first name",
			lettersonly: "Please only use letters"
		},
		lname: {
			required: "Please enter your last name",
			lettersonly: "Please only use letters"
		},
		address: {
			required: "Please enter your permanent address"
		},
		city: {
			required: "Please enter your city",
			lettersonly: "Please only use letters"
		},
		state: {
			required: "Please choose a state from the drop down list"
		},
		zip: {
			required: "Please enter your zip",
			minlength: "Please enter in your 5 or 9 digit zip code",
			zip: "Please enter your zip correctly: (e.g. 99999 or 99999-9999)"
		},
		phone: {
			required: "Please enter your phone number",
			phoneUS: "Please enter a valid phone number: (e.g. 19999999999 or 9999999999)"
		},
		email: {
			required: "Please enter your email address",
			email: "Please enter a valid email address: (e.g. [email protected])",
			remote: "That email address is already registered"
		},
		ver_email: {
			equalTo: "Your email addresses do not match"
		},
		institution: {
			required: "Please enter the name of your institution"
		},
		type: {
			required: "Please select your the appropriate type for your institution"
		},
		address_sch: {
			required: "Please enter the address of your institution"
		},
		prize_name: {
			required: "Please enter the name of your prize"
		},
		descr: {
			required: "Please enter in a description of your prize"
		},
		retail: {
			required: "Please enter in the retail value of your prize",
			digits: "Please only use numbers"
		},
		iitdescr: {
			required: "Please provide a brief descrition of the institution"
		},
		typedescr: {
			required: "Please provide a brief description of the type"
		},
		iitype: {
			required: "Please select an option from the list, if none are appropriate please select 'Other'"
		},
		type: {
			required: "Please select an option from the list, if none are appropriate please select 'Other'"
		},
		username: {
			required: "Please enter an username",
			remote: "Username is already taken"
		},
		password: {
			required: "Please enter a password that is a minimum of 8 characters and containers 1 upper case, 1 symbol, and 1 number"
		},
		password_verify: {
			required: "Please reenter your password to verify",
			equalTo: "Your passwords did not match"
		},
		regis_code: {
			required: "Please enter a registration code",
			remote: "That registration code limit has been reached. If you do not know any other code, please restart the registration process and select a different option or contact your STEM center directly."
		},
		"workshop" : "Please select an option"
	},
	errorPlacement: function (error, element) {
		if (element.is("input:radio")) {
			element.parents("div:first").before(error);
		} else {
			element.after(error);
		}
	}
});