PageSourceSearch

https://pnri.org/wp-content/themes/hotpepper_v5/assets/js/hp-validate.js?ver=5.0.1790242211

js pnri.org collected 2026-09-24 09:31:06 UTC 9,634 bytes, 314 lines download raw bytes

1/**
2* VALIDATIONS ====================
3updated 2022-08-19 TW
4updated 2020-06-22 TW
5updated 2020-02-28 TW
6
7// NOTE: ONLY call these functions from inside jQuery(document).ready(function($) {}); to maintain scope!!!!!
8ex:
9function checkme() {
10	jQuery(document).ready(function($) {
11		$pass = check_blank($(this),$msg);
12	});// /jQuery(document).ready(function($) {
13}
14*/
15
16/*
17check_blank()
18check_blank_no_email()
19check_cc_num()
20check_ccv()
21check_checkbox()
22check_checkboxgrp()
23check_email()
24check_match_a_b()
25check_min_max()
26check_radio()
27check_radio_grp()
28check_select()
29*/
30
31function check_blank() {
32	var $args = arguments;
33	var $pass = true;
34	var $obj = $args[0];
35	var $fd = 'required';
36	if (typeof $obj.attr('title') != 'undefined') {$fd = $obj.attr('title');}
37	else if (typeof $obj.attr('id') != 'undefined') {$fd = $obj.attr('id');}
38	else if (typeof $obj.attr('name') != 'undefined') {$fd = $obj.attr('name');}
39	var $msg = 'Please fill out the "'+$fd+'" field';
40	if (typeof $args[1] != 'undefined' && $args[1] != '') {$msg = $args[1];}
41	
42	if ($obj.val() == '') {
43		$obj.focus();
44		if ($msg != null) {
45			alert($msg);
46		}
47		$pass = false;
48	}
49	return $pass;
50}// /function check_blank() {
51
52function check_blank_no_email() {
53	var $args = arguments;
54	var $pass = true;
55	var $obj = $args[0];
56	var $fd = 'required';
57	if (typeof $obj.attr('title') != 'undefined') {$fd = $obj.attr('title');}
58	else if (typeof $obj.attr('id') != 'undefined') {$fd = $obj.attr('id');}
59	else if (typeof $obj.attr('name') != 'undefined') {$fd = $obj.attr('name');}
60	var $msg_blank = 'Please fill out the "'+$fd+'" field';
61	var $msg_email = 'The "'+$fd+'" field cannot be an email address.';
62	if (typeof $args[1] != 'undefined' && $args[1] != '') {$msg = $args[1];}
63	// first check if is blank
64	if ($obj.val() == '') {
65		$obj.focus();
66		alert($msg_blank);
67		return false;
68	}
69	// now check that value does NOT equal email format
70	if ($obj.val().search(/^([\w\.-])+@(([\w\.-])+)+\.([a-zA-Z0-9]){2,253}$/) !== -1) {
71		$obj.focus();
72		alert($msg_email);
73		$pass = false;
74	}
75	return $pass;
76}// /function check_blanknoemail() {
77
78function check_cc_num() {
79	var $args = arguments;
80	var $pass = true;
81	var $obj = $args[0];
82	if (typeof $args[1] != 'undefined' && $args[1] != '') {var $msg = $args[1];}
83	
84	var ccnumValue = $obj.val().trim().replace(/\D+/g, "");
85	var ccnumLength = ccnumValue.length;
86	var ccnumPrefix1 = parseInt(ccnumValue.substr(0,1));
87	var ccnumPrefix2 = parseInt(ccnumValue.substr(0,2));
88	var ccnumPrefix3 = parseInt(ccnumValue.substr(0,3));
89	var ccnumPrefix4 = parseInt(ccnumValue.substr(0,4));
90	
91	var cctypeValue = "";
92	if ((ccnumPrefix2 >= 51 && ccnumPrefix2 <= 55)) {cctypeValue = "MasterCard";}
93	if (ccnumPrefix1 == 4) {cctypeValue = "Visa";}
94	
95	if (cctypeValue == "") {
96		$obj.focus();
97		alert("The Credit Card number you entered does not seem to be either a Visa or MasterCard number. Only Visa/MC are accepted.");
98		$pass = false;
99	}
100	else {
101		if (cctypeValue == "MasterCard") {
102			if (ccnumLength != 16) {$pass = false;}
103			if (!(ccnumPrefix2 >= 51 && ccnumPrefix2 <= 55)) {$pass = false;}
104		}
105		if (cctypeValue == "Visa") {
106			if (!(ccnumLength == 16 || ccnumLength == 13)) {$pass = false;}
107			if (ccnumPrefix1 != 4) {$pass = false;}
108		}
109		var sum = 0;
110		for (var n = 1; n <= ccnumLength; n++) {
111			var i = parseInt(ccnumValue.substr(((ccnumLength) - n), 1));
112			//alert(i);
113			if (n%2 == 0) {
114				var i2 = (i * 2)+"";
115				//alert("even numbers i = "+i+"; i*2 = "+i2);
116				if (parseInt(i2) > 9) {
117					var i2char1 = i2.substr(0,1);
118					var i2char2 = i2.substr(1,1);
119					var i2 = parseInt(i2char1) + parseInt(i2char2);
120				}
121				sum = sum + parseInt(i2);
122				//alert("even numbers i = "+i+"; i2 with addition = "+i2);
123			}
124			else {sum = sum + i;}
125		}
126		if ((sum % 10) > 0) {$pass = false;}
127		
128		if (!$pass) {
129			alert($msg);
130		}
131	}
132	return $pass;
133}// /function check_cc_num() {
134
135function check_ccv() {
136	var $args = arguments;
137	var $pass = true;
138	var $obj = $args[0];
139	
140	var $msg = 'Please provide your Credit Card verification number. It is the last 3 digits on the back of the card.';
141	if (typeof $args[1] != 'undefined' && $args[1] != '') {$msg = $args[1];}
142	
143	var v = $obj.val().trim().replace(/\D+/g, "");
144	if (v.length < 3 && v.length < 4) {
145		$obj.focus();
146		alert($msg);
147		$pass = false;
148	}
149	return $pass;
150}// /function check_ccv() {
151
152function check_checkbox() {
153	var $args = arguments;
154	var $pass = true;
155	var $obj = $args[0];
156	
157	var $fd = 'required';
158	if (typeof $obj.attr('title') != 'undefined') {$fd = $obj.attr('title');}
159	else if (typeof $obj.attr('id') != 'undefined') {$fd = $obj.attr('id');}
160	else if (typeof $obj.attr('name') != 'undefined') {$fd = $obj.attr('name');}
161	var $msg = 'Please check the "'+$fd+'" box.';
162	if (typeof $args[1] != 'undefined' && $args[1] != '') {$msg = $args[1];}
163	
164	if (typeof $obj.checked == 'undefined') {$obj.checked = $obj.attr('checked');}
165	if (!$obj.checked) {
166		$obj.focus();
167		alert($msg);
168		$pass = false;
169	}
170	return $pass;
171}// /function check_checkbox() {
172
173function check_checkboxgrp() {
174	var $args = arguments;
175	var $pass = true;
176	return $pass;
177}// /function check_checkboxgrp() {
178
179function check_email() {
180	var $args = arguments;//console.log('$args:',$args);
181	var $pass = true;
182	var $obj = $args[0];
183	
184	var $fd = 'required';
185	if (typeof $obj.attr('title') != 'undefined') {$fd = $obj.attr('title');}
186	else if (typeof $obj.attr('id') != 'undefined') {$fd = $obj.attr('id');}
187	else if (typeof $obj.attr('name') != 'undefined') {$fd = $obj.attr('name');}
188	var $msg = 'There is a problem with the "'+$fd+'" field, please check that there are no typos and try again';
189	if (typeof $args[1] != 'undefined' && $args[1] != '') {$msg = $args[1];}
190	
191	if (typeof $obj.val() == 'undefined') {$obj.val() = $obj.val();}
192	if (
193	$obj.val().indexOf('@') == -1
194	|| $obj.val().search(/^([\w\.-])+@(([\w\.-])+)+\.([a-zA-Z0-9]){2,253}$/)
195	) {
196		$obj.focus();
197		alert($msg);
198		$pass = false;
199	}
200	return $pass;
201}// /function check_email() {
202
203function check_match_a_b() {
204	var $args = arguments;
205	var $pass = true;
206	// useful for password, password_confirm fields
207	var $a = $args[0];
208	var $b = $args[1];
209	
210	if ($a.attr('title') != 'undefined') {$a_fd = $a.attr('title');}
211	else if ($a.attr('id') != 'undefined') {$a_fd = $a.attr('id');}
212	else if ($a.attr('name') != 'undefined') {$a_fd = $a.attr('name');}
213	
214	if ($b.attr('title') != 'undefined') {$b_fd = $b.attr('title');}
215	else if ($b.attr('id') != 'undefined') {$b_fd = $b.attr('id');}
216	else if ($b.attr('name') != 'undefined') {$b_fd = $b.attr('name');}
217	
218	var $msg = 'The "'+$a_fd+'" field and the "'+$b_fd+'" field MUST match exactly. Please try again.';
219	if (typeof $args[2] != 'undefined' && $args[2] != '') {$msg = $args[2];}
220	
221	if ($a.val() != $b.val()) {
222		$a.focus();
223		alert($msg);
224		$a.val('');
225		$b.val('');
226		$pass = false;
227	}
228	return $pass;
229}// /function check_match_a_b() {
230
231function check_min_max() {
232	var $args = arguments;
233	var $pass = true;
234	var $obj = $args[0];
235	var $minlength = $args[1];
236	var $maxlength = $args[2];
237	
238	if ($obj.attr('title') != 'undefined') {$label = $obj.attr('title');}
239	else if ($obj.attr('id') != 'undefined') {$label = $obj.attr('id');}
240	else if ($obj.attr('name') != 'undefined') {$label = $obj.attr('name');}
241	
242	var $pass = true;
243	if($obj.val().length < $minlength) {
244		$pass = false;
245		var $msg = $label+' requires a minimum of '+$minlength+' characters.';
246	}// /if($obj.val().length < $minlength) {
247	if($obj.val().length > $maxlength) {
248		$pass = false;
249		var $msg = $label+' cannot be more than '+$maxlength+' characters.';
250	}// /if($obj.val().length > $maxlength) {
251	
252	if (!$pass) {
253		$obj.val('');
254		$obj.focus();
255		alert($msg);
256	}
257	return $pass;
258}// /function check_min_max() {
259
260function check_radio() {
261	var $args = arguments;
262	var $pass = true;
263	var $label = $args[0];
264	var $obj = $args[1];
265	
266	var $msg = 'Please select an item from the "'+$label+'" list';
267	if (typeof $args[2] != 'undefined' && $args[2] != '') {var $msg = $args[2];}
268	
269	if (typeof $obj.val() == 'undefined') {
270		$obj.focus();
271		alert($msg);
272		$pass = false;
273	}
274	return $pass;
275}// /function check_radio() {
276
277function check_radio_grp() {
278	var $args = arguments;
279	var $pass = true;
280	var $obj = $args[0];
281	var $msg = 'Please select an item from the "'+$obj.attr('title')+'" list';
282	if (typeof $args[1] != 'undefined' && $args[1] != '') {var $msg = $args[1];}
283	var $name = $obj.attr('name');
284	if ($('input[name="'+$name+'"]:checked').length == 0) {
285		$obj.focus();
286		alert($msg);
287		$pass = false;
288	}
289	return $pass;
290}// /function check_radio2() {
291
292function check_select() {
293	var $args = arguments;
294	var $pass = true;
295	var $obj = $args[0];
296	
297	var $fd = 'required';
298	if (typeof $obj.attr('title') != 'undefined') {$fd = $obj.attr('title');}
299	else if (typeof $obj.attr('id') != 'undefined') {$fd = $obj.attr('id');}
300	else if (typeof $obj.attr('name') != 'undefined') {$fd = $obj.attr('name');}
301	var $msg = 'Please select an item from the "'+$fd+'" list';
302	if (typeof $args[1] != 'undefined' && $args[1] != '') {$msg = $args[1];}
303	
304	// NOTE: for this to trigger, the first option MUST be set like
304: <option value="">text here</option> otherwise, the text gets returned :(
305	if (
306	$obj.prop('selectedIndex') == 0 
307	&& $obj.val() == ''
308	) {
309		$obj.focus();
310		alert($msg);
311		$pass = false;
312	}
313	return $pass;
314}// /function check_select() {

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.