PageSourceSearch

https://www.flikvlooi.co.za/js/profile_base.r40242.js

js flikvlooi.co.za collected 2026-10-04 03:37:22 UTC 15,011 bytes, 394 lines download raw bytes

1// $Id: profile_base.js 38265 2024-12-11 08:16:40Z brendon $
2// Functions to support validation of join, join_access & profile_base
3
4// Variables to be populated in the HTML: 
5// none, but valStrings should come from requiredFields.js
6
7// Username validation
8function checkUsername (formElement, relaxed) {
9	valStrings["username"] = formElement.value;
10	var wordChars = 'a-zA-Z0-9_\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\xFF';  // Latin-1 Supplement (ISO-8859-1 extended) characters
11	var validUsernameRegExp = RegExp('^[' + wordChars + ']{3,20}$');
12	var emailServicesRegex = /(gmail|yahoo|hotmail|icloud)(co(m|uk))?/i;
13	if (!formElement.value) {
14		return false;
15	} else if (formElement.value && !formElement.value.match(validUsernameRegExp)) {
16		var invalidUsernameRegExp = RegExp('[^' + wordChars + ']', 'g');
17		formElement.value = formElement.value.replace(invalidUsernameRegExp, '');
18		processInputFieldValue(formElement, valStrings["usernameLength"], 3);
19		return false;
20	} else if (formElement.value && formElement.value.match(/\d/g) && formElement.value.match(/\d/g).length > 4) {
21		formElement.value = formElement.value.replace(/\d/g, '');
22		processInputFieldValue(formElement, valStrings["usernameDigits"], 3);
23		return false;
24	} else if (formElement.form.email && formElement.form.email.value) {
25		// check username for presence of email username
26		var emailStr = formElement.form.email.value;
27		emailStr = jQuery.trim(emailStr);
28		var emailPat = /^(.+)@(.+)$/;
29		var matchArray = emailStr.match(emailPat);
30		if (matchArray != null) {
31			var user = matchArray[1];
32			var r = (typeof relaxed != "undefined") ? relaxed : false;	
33			// See if "user" matches username
34			if (!r && formElement.value && user.toLowerCase() == formElement.value.toLowerCase()) {
35				alert(valStrings["emailUsername"]);
36				formElement.value = "";
37				formElement.focus();
38				return false;
39			} else{
40				// match and remove those domains from the username
41				if (formElement.value.match(emailServicesRegex)) {
42					formElement.value = stripEmailService(formElement.value);
43					processInputFieldValue(formElement, valStrings["usernameDomains"], 3);
44					return false;
45				}
46			}			
47		}
48		return true;
49	} else {
50		// match and remove those domains from the username
51		if (formElement.value.match(emailServicesRegex)) {
52			formElement.value = stripEmailService(formElement.value);
53			processInputFieldValue(formElement, valStrings["usernameDomains"], 3);
54			return false;
55		}
56		return true;
57	}
58}
59
60function stripEmailService(username) {
61	// Define a regular expression for common email services
62	var emailServicesRegex = /(gmail|yahoo|hotmail|icloud)(co(m|uk))?/i;
63	// Remove the email service domain from the username string
64	return username.replace(emailServicesRegex, '');
65}
66
67// Checks that two email address fields match
68function checkEmails (checkForm) {
69	if (checkForm.email.value == checkForm.email2.value) {
70		return true;
71	} else {
72		alert (valStrings["emailMismatch"]);
73		checkForm.email.value = checkForm.email2.value = '';
74		checkForm.email.focus();
75		return false;
76	}
77}
78
79// Activation code validation
80function checkActivationCode (formElement) {
81	if (!formElement.value.match(/^[a-zA-Z]{3}[1-9]{3}$/) && formElement.value) {
82		alert(valStrings["badActivationFormat"]); 
83		formElement.value = '';
84		formElement.focus();
85		return false;
86	} else {
87		return true;
88	}
89}
90
91// Checks length bounds on a single password
92function checkPassword (formElement) {
93	
94	/**
95	 * Explanation of regex below:
96	 * /^			- Anchor to start of string
97	 * (?=.*[a-z])	- Assert whether at least one lowercase character exists
98	 * (?=.*[A-Z])	- Assert whether at least one UPPERCASE character exists
99	 * (?=.*[0-9])	- Assert whether at least one digit exists
100	 * .{8,}		- string must be a minimum of 8 characters
101	 * $/			- end of string
102	 */	 	
103	if (valStrings["enforceStrongerPasswords"]) {
104		if (formElement.value && formElement.value.match(/^(?=.{8,}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*/) == null) {
105			alert(valStrings["passwordRules"]);
106			formElement.value = '';
107			formElement.focus();
108			return false;
109		}
110	} else {
111		if (formElement.value && formElement.value.length < 6) {
112			alert(valStrings["passwordLength"]);
113			formElement.value = '';
114			formElement.focus();
115			return false;
116		}
117
118		if (formElement.value && formElement.value.match(/^[0-9]+$/)) {
119			alert(valStrings["passwordAllNumeric"]); 
120			formElement.value = '';
121			formElement.focus();
122			return false;
123		}
124	}
125	
126	if (formElement.form.username.length && formElement.value.toLowerCase() == formElement.form.username.value.toLowerCase()) {
127		alert(valStrings["passwordUsername"]); 
128		formElement.value = '';
129		formElement.focus();
130		return false;
131	}
132	
133	// Verify that the password field does NOT contain any part of the username
134	if (formElement.value.length && formElement.form.username.value.toLowerCase().match(formElement.value.toLowerCase())) {
135		alert(valStrings["passwordUsernameStrMatch"]);
136		formElement.value = '';
137		formElement.focus();
138		return false;
139	}
140	return true;
141}
142
143// Checks that two password fields match
144function checkPasswords (checkForm) {
145	if (checkForm.password.value == checkForm.password2.value) {
146		return true;
147	} else {
148		alert (valStrings["passwordMismatch"]);
149		checkForm.password.value = checkForm.password2.value = '';
150		checkForm.password.focus();
151		return false;
152	}
153}
154
155// Check if we have a single-province autonomous region selected
156function checkProvince (provinceElement) {
157	if (provinceElement.options[provinceElement.selectedIndex].text.substr(0,3) == "---") {
158		provinceElement.selectedIndex += 1;
159	}
160}
161
162// Checks for default firstName
163function checkFirstName (formElement) {
164	if (formElement.value == valStrings["defaultFirstName"]) {
165		var alertString = '"' + formElement.value + '" ' + valStrings["err_badFirstName"];
166		processInputFieldValue(formElement, alertString);
167		return false;
168	} else {
169		return true;
170	}
171}
172
173// Verify that the password does NOT contain any part of the first name
174function comparePasswordName (formElement, password) {
175	if (formElement.value.toLowerCase().match(password.value.toLowerCase()) && formElement.value) {
176		alert(valStrings["passwordUsernameStrMatch"]);
177		password.value = password.form.password2.value = '';
178		password.focus();
179		return false;
180	}
181	
182	return true;
183}
184
185// Run a password value through our suite of password checks
186function doAllPasswordChecks (checkForm) {
187	return (checkPassword (checkForm.password)
188		&& checkPasswords (checkForm)
189		&& comparePasswordName (checkForm.firstName, checkForm.password)
190		&& comparePasswordName (checkForm.surname, checkForm.password));
191}
192
193// Checks for default surname
194function checkSurname (formElement) {
195	if (formElement.value == valStrings["defaultSurname"]) {
196		var alertString = '"' + formElement.value + '" ' + valStrings["err_badSurname"];
197		processInputFieldValue(formElement, alertString);
198		return false;
199	} else {
200		return true;
201	}
202}
203
204// Check DOB validity and check for underage users.
205function checkBirthDate (formElement) {
206	var year = parseFloat(formElement.form.birthDateYear.options[formElement.form.birthDateYear.selectedIndex].text);
207	var month = parseFloat(formElement.form.birthDateMonth.options[formElement.form.birthDateMonth.selectedIndex].value);
208	var day = parseFloat(formElement.form.birthDateDay.options[formElement.form.birthDateDay.selectedIndex].text);
209	var birthDate = new Date (year, (month - 1), day);
210	if (day != birthDate.getDate() || (month-1) != birthDate.getMonth() || year != birthDate.getFullYear()) {
211		alert(valStrings["invalidBirthDate"]);
212		formElement.focus();
213		return false;
214	}
215
216	// assume year dropdown options are in descending order
217	var firstYearIndex = 0;
218	if (isNaN(formElement.form.birthDateYear.options[firstYearIndex].text)) {
219		// account for label as first option
220		firstYearIndex++;
221	}
222	if (parseFloat(formElement.form.birthDateYear.options[formElement.form.birthDateYear.length-1].text) > parseFloat(formElement.form.birthDateYear.options[firstYearIndex].text)) {
223		// year dropdown options are in ascending order
224		firstYearIndex = formElement.form.birthDateYear.length-1;
225	}
226	var minAge = serverDate.substr(0,4) - parseFloat(formElement.form.birthDateYear.options[firstYearIndex].text);
227	var birthMin = new Date (serverDate.substr(0,4) - minAge, serverDate.substr(5,2) - 1, serverDate.substr(8,2));
228	if (birthDate.getTime() > birthMin.getTime()) {
229		alert(valStrings["tooYoung"]);
230		formElement.focus();
231		return false;
232	}
233	return true;
234}
235
236// Manage the mGender value when mGender selection has been disallowed
237function autosetMGender(formElement) {
238	if (typeof formElement.form.elements["mGender[]"] != 'undefined') {
239		var mGenderElement = formElement.form.elements["mGender[]"];
240	} else {
241		var mGenderElement = formElement.form.mGender;
242	}
243	
244	if (mGenderElement.value != 3) {
245		// when mGender is not set to Men & Women...
246		var gender = formElement.value;
247		var mGender = gender ^ 3;  // set mGender to the inverse of gender
248		if (mGenderElement.value != gender) {
249			mGender = gender;  // set mGender to match gender
250		}
251		//change the text label for mGender
252		$(mGenderElement).prev("span.gender").html(menWomen[mGender]);
253		//change the numeric value in the hidden input field
254		mGenderElement.value = mGender; 
255	}
256	return true;
257}
258
259// Check that min & max are the right way round and importance is correct
260function checkAgeRange (formElement) {
261	var mAgeMin = formElement.form.mAgeMin.selectedIndex;
262	var mAgeMax = formElement.form.mAgeMax.selectedIndex;
263	if (mAgeMax < mAgeMin) {
264		formElement.form.mAgeMin.options[mAgeMin].selected = false;
265		formElement.form.mAgeMax.options[mAgeMax].selected = false;
266		formElement.form.mAgeMin.options[mAgeMax].selected = true;
267		formElement.form.mAgeMax.options[mAgeMin].selected = true;
268	}
269	return true;
270}
271
272// Conditions for form submission
273function submitJoin (checkForm, relaxed) {
274	return (checkRequiredFields(checkForm) 
275		&& checkUsername (checkForm.username)
276		&& checkEmails (checkForm)
277		&& checkEmail (checkForm.email, relaxed)
278		&& checkEmail (checkForm.email2, relaxed));
279}
280
281function submitAffiliatesJoin (checkForm) {
282	return (checkRequiredFields(checkForm) 
283		&& checkUsername (checkForm.username)
284		&& checkEmail (checkForm.email));
285}
286
287function submitJoin_v2 (checkForm, relaxed) {
288	var interimResult = checkRequiredFields(checkForm);
289	interimResult = interimResult && checkUsername (checkForm.username);
290	if (typeof checkForm.password != 'undefined') { interimResult = interimResult && checkPassword (checkForm.password); }
291	if (typeof checkForm.password2 != 'undefined') { interimResult = interimResult && checkPasswords (checkForm); }
292	if (typeof checkForm.firstName != 'undefined') { interimResult = interimResult && comparePasswordName (checkForm.firstName, checkForm.password); }
293	if (typeof checkForm.surname != 'undefined') { interimResult = interimResult && comparePasswordName (checkForm.surname, checkForm.password); }
294	if (typeof valStrings["defaultFirstName"] != "undefined") {
295		interimResult = interimResult && checkFirstName (checkForm.firstName);
296		interimResult = interimResult && checkSurname (checkForm.surname);
297	}
298	if (typeof checkForm.email2 == "undefined" || checkForm.email2.value == "[suppressed]") {
299		interimResult = interimResult && checkEmail (checkForm.email, relaxed);
300	} else {
301		interimResult = interimResult && checkEmails (checkForm);
302		interimResult = interimResult && checkEmail (checkForm.email, relaxed);
303		interimResult = interimResult && checkEmail (checkForm.email2, relaxed);
304	}
305	if (typeof checkForm.birthDateDay != "undefined") {
306		interimResult = interimResult && checkBirthDate (checkForm.birthDateDay);
307	}
308	if (typeof valStrings["invalidPostCodeFormat"] != "undefined" && checkForm.countryID.options[checkForm.countryID.selectedIndex].value == "uk") {
309		interimResult = interimResult && validatePostCodeUK(checkForm.postCode, false, true);
310	}
311	
312	return interimResult;
313}
314
315function submitJoin_access (checkForm) {
316	return (checkRequiredFields(checkForm) 
317		&& checkActivationCode (checkForm.activationCode)
318		&& doAllPasswordChecks (checkForm));
319}
320
321// Function used by the new profile_base template
322function submitProfile_basicDetails (checkForm, relaxed) {
323	return (checkRequiredFields(checkForm));
324}
325
326// Old function currently still being used by the affiliates_details template
327function submitProfile_base (checkForm, relaxed) {
328	if (typeof(checkForm.password) != "undefined" && (checkForm.password.value || checkForm.password2.value)) {
329		return (checkRequiredFields(checkForm) 
330			&& checkUsername (checkForm.username)
331			&& checkEmail (checkForm.email, relaxed)
332			&& doAllPasswordChecks (checkForm));
333	} else {
334		return (checkRequiredFields(checkForm) 
335			&& checkUsername (checkForm.username)
336			&& checkEmail (checkForm.email, relaxed));
337	}
338}
339
340function submitProfile_clone (checkForm) {
341	return (checkRequiredFields(checkForm)
342		&& checkUsername (checkForm.username)
343		&& doAllPasswordChecks (checkForm));
344}
345
346// If you click anything after the "later" option, later has to be unchecked
347// unless you've just unchecked the last of the other checked items.
348// Originally uncheckLater - called often, so HTML is optimised by shortening
349function uL (formElement) {
350	var firstElement = 0;
351	var gotAnother = false;
352	for (var i = formElementIndex[formElement.name]; i < formElement.form.elements.length; i++) {
353		if (formElement.form.elements[i].name == formElement.name) {
354			if (firstElement) {
355				gotAnother = (gotAnother || formElement.form.elements[i].checked);
356			} else if (formElement.form.elements[i].value == 0) {
357				firstElement = i;
358				formElement.form.elements[i].checked = false;
359				$(formElement.form.elements[i]).closest("div.checkWrapper").removeClass("active");
360			}
361		} else if (firstElement) {
362			break;  // terminate the loop when we go on to another form element.
363		}
364	}
365	if (!gotAnother) {
366		formElement.form.elements[firstElement].checked = true;
367	}
368}
369
370// If you click the later option, we have to clear all the others,
371// but ensure that later stays checked.
372// Originally checkLater - called often, so HTML is optimised by shortening
373function cL (formElement) {
374	resetCheckboxes (formElement.form, formElement.name);
375}
376
377// Reset a given set of checkboxes
378// Modified by warrenski 2007-01-16, to refer directly to form elements instead of relying on their position in the entire form
379function resetCheckboxes (formObject, formElementName, firstElementValue, laterElementValue) {
380	if (typeof firstElementValue == "undefined") { firstElementValue = true; }
381	if (typeof laterElementValue == "undefined") { laterElementValue = false; }
382	var gotFirstElement = false;
383	var elements = formObject.elements[formElementName];
384	for (var i = 0; i < elements.length; i++) {
385		if (gotFirstElement) {
386			elements[i].checked = laterElementValue;
387			$(elements[i]).closest("div.checkWrapper").removeClass("active");
388		} else {
389			elements[i].checked = firstElementValue;
390			$(elements[i]).closest("div.checkWrapper").addClass("active");
391			gotFirstElement = true;
392		}
393	}
394}

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.