PageSourceSearch

https://www.sneddontheatre.co.za/media/system/js/validate.js

js sneddontheatre.co.za collected 2026-10-06 20:25:45 UTC 4,246 bytes, 166 lines download raw bytes

1/**
2* @version		$Id: validate.js 7401 2007-05-14 04:12:55Z eddieajau $
3* @package		Joomla
4* @copyright	Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
5* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
6* Joomla! is free software. This version may have been modified pursuant
7* to the GNU General Public License, and as distributed it includes or
8* is derivative of works licensed under the GNU General Public License or
9* other free or open source software licenses.
10* See COPYRIGHT.php for copyright notices and details.
11*/
12
13/**
14 * Unobtrusive Form Validation library
15 *
16 * Inspired by: Chris Campbell <www.particletree.com>
17 *
18 * @package		Joomla.Framework
19 * @subpackage	Forms
20 * @since		1.5
21 */
22var JFormValidator = new Class({
23	initialize: function()
24	{
25		// Initialize variables
26		this.handlers	= Object();
27		this.custom		= Object();
28
29		// Default handlers
30		this.setHandler('username',
31			function (value) {
32				regex = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&]", "i");
33				return !regex.test(value);
34			}
35		);
36
37		this.setHandler('password',
38			function (value) {
39				regex=/^\S[\S ]{2,98}\S$/;
40				return regex.test(value);
41			}
42		);
43
44		this.setHandler('numeric',
45			function (value) {
46				regex=/^(\d|-)?(\d|,)*\.?\d*$/;
47				return regex.test(value);
48			}
49		);
50
51		this.setHandler('email',
52			function (value) {
53				regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
54				return regex.test(value);
55			}
56		);
57
58		// Attach to forms with class 'form-validate'
59		var forms = $$('form.form-validate');
60		forms.each(function(form){ this.attachToForm(form); }, this);
61	},
62
63	setHandler: function(name, fn, en)
64	{
65		en = (en == '') ? true : en;
66		this.handlers[name] = { enabled: en, exec: fn };
67	},
68
69	attachToForm: function(form)
70	{
71		// Iterate through the form object and attach the validate method to all input fields.
72		$A(form.elements).each(function(el){
73			el = $(el);
74			if ((el.getTag() == 'input' || el.getTag() == 'button') && el.getProperty('type') == 'submit') {
75				if (el.hasClass('validate')) {
76					el.onclick = function(){return document.formvalidator.isValid(this.form);};
77				}
78			} else {
79				el.addEvent('blur', function(){return document.formvalidator.validate(this);});
80			}
81		});
82	},
83
84	validate: function(el)
85	{
86		// If the field is required make sure it has a value
87		if ($(el).hasClass('required')) {
88			if (!($(el).getValue())) {
89				this.handleResponse(false, el);
90				return false;
91			}
92		}
93
94		// Only validate the field if the validate class is set
95		var handler = (el.className && el.className.search(/validate-([a-zA-Z0-9\_\-]+)/) != -1) ? el.className.match(/validate-([a-zA-Z0-9\_\-]+)/)[1] : "";
96		if (handler == '') {
97			this.handleResponse(true, el);
98			return true;
99		}
100
101		// Check the additional validation types
102		if ((handler) && (handler != 'none') && (this.handlers[handler]) && $(el).getValue()) {
103			// Execute the validation handler and return result
104			if (this.handlers[handler].exec($(el).getValue()) != true) {
105				this.handleResponse(false, el);
106				return false;
107			}
108		}
109
110		// Return validation state
111		this.handleResponse(true, el);
112		return true;
113	},
114
115	isValid: function(form)
116	{
117		var valid = true;
118
119		// Validate form fields
120		for (var i=0;i < form.elements.length; i++) {
121			if (this.validate(form.elements[i]) == false) {
122				valid = false;
123			}
124		}
125
126		// Run custom form validators if present
127		$A(this.custom).each(function(validator){
128			if (validator.exec() != true) {
129				valid = false;
130			}
131		});
132
133		return valid;
134	},
135
136	handleResponse: function(state, el)
137	{
138		// Find the label object for the given field if it exists
139		if (!(el.labelref)) {
140			var labels = $$('label');
141			labels.each(function(label){
142				if (label.getProperty('for') == el.getProperty('id')) {
143					el.labelref = label;
144				}
145			});
146		}
147
148		// Set the element and its label (if exists) invalid state
149		if (state == false) {
150			el.addClass('invalid');
151			if (el.labelref) {
152				$(el.labelref).addClass('invalid');
153			}
154		} else {
155			el.removeClass('invalid');
156			if (el.labelref) {
157				$(el.labelref).removeClass('invalid');
158			}
159		}
160	}
161});
162
163document.formvalidator = null;
164Window.onDomReady(function(){
165	document.formvalidator = new JFormValidator();
166});

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.