PageSourceSearch

https://ouatsports.com/wp-content/plugins/swpm-form-builder/js/swpm-validation.js?ver=5.4.8

js ouatsports.com collected 2026-10-02 18:54:44 UTC 4,923 bytes, 150 lines download raw bytes

1jQuery(document).ready(function ($) {
2	// !Validate each form on the page
3	$('.swpm-form-builder').each(function () {
4		const form = this; // The reference of current form beign iterated.
5		
6		let rules = {}; // To add custom rules for different fields.
7		let messages = {}; // To add custom validation messages.
8
9		// Dynamically get the 'name' attribute value of input field which contains the classname 'uniqueUsername'. 
10		// This 'name' attribute value is used to define custom rules and validation messages.
11		const username_field_name_attr = $(form).find('.uniqueUsername').attr('name');
12		rules[username_field_name_attr] = {
13			remote: {
14				type: "get",
15				url: swpmFbAjaxFieldValidation.ajax_url,
16				data: {
17					action: "swpm_validate_user_name",
18					nonce: swpmFbAjaxFieldValidation.nonce,
19					fieldId: 'username',
20					fieldValue: function() {
21						return $(form).find('.uniqueUsername').val();
22					}
23				},
24				dataFilter: function (response) {
25					response = JSON.parse(response);
26					return response[1];
27				},
28			}
29		}
30		messages[username_field_name_attr] = {
31			remote: $.validator.messages.uniqueUsername || 'Username already taken',
32		};
33        
34		// Dynamically get the 'name' attribute value of input field which contains the classname 'uniqueEmail'. 
35		// This 'name' attribute value is used to define custom rules and validation messages.
36		const email_field_name_attr = $(form).find('.uniqueEmail').attr('name');
37		rules[email_field_name_attr] = {
38			remote: {
39				type: "get",
40				url: swpmFbAjaxFieldValidation.ajax_url,
41				data: {
42					action: "swpm_validate_email",
43					nonce: swpmFbAjaxFieldValidation.nonce,
44					fieldId: 'username',
45					fieldValue: function() {
46						return $(form).find('.uniqueEmail').val();
47					}
48				},
49				dataFilter: function (response) {
50					response = JSON.parse(response);
51					return response[1];
52				},
53			}
54		}
55		messages[email_field_name_attr] = {
56			remote: $.validator.messages.uniqueEmail || 'Email address already taken',
57		};
58
59		rules['swpm-secret'] = {
60			required: true,
61			digits: true,
62			maxlength: 2
63		};
64
65		$(this).validate({
66			rules: rules,
67			errorClass: 'swpm-form-builder-error',
68			errorPlacement: function (error, element) {
69				if (element.is(':radio') || element.is(':checkbox'))
70					error.appendTo(element.parent().parent());
71				else if (element.is(':password'))
72					error.insertAfter(element);
73				else
74					error.insertAfter(element);
75			},
76			submitHandler: function (form) {
77				var invalid = false;
78				$('.swpm-checkbox-required').each(function () {
79					var multicheck = $(this);
80					if (multicheck.find('input:checked').length < 1) {
81						invalid = true;
82						if (multicheck.find('label.swpm-error').length === 0) {
83							$('<label generated="true" class="swpm-error">' + swpmFbValidation.str.checkOne + '</label>')
84								.appendTo(multicheck);
85						}
86					}
87				});
88				if (invalid) {
89					return false;
90				} else {
91					form.submit();
92					return true;
93				}
94			},
95			messages: messages,
96		});
97	});
98
99	// Force bullets to hide, but only if list-style-type isn't set
100	$('.swpm-form-builder li:not(.swpm-item-instructions li, .swpm-span li)').filter(function () {
101		return $(this).css('list-style-type') !== 'none';
102	}).css('list-style', 'none');
103
104	// !Display jQuery UI date picker
105	$('.swpm-date-picker').each(function () {
106		var swpm_dateFormat = $(this).attr('data-dp-dateFormat') ? $(this).attr('data-dp-dateFormat') : 'mm/dd/yy';
107
108		$(this).datepicker({
109			dateFormat: swpm_dateFormat,
110			yearRange: "-100:+100",
111			changeMonth: true,
112			changeYear: true
113		});
114	});
115
116	// !Custom validation method
117	$.validator.addMethod('phone', function (value, element) {
118		// Strip out all spaces, periods, dashes, parentheses, and plus signs
119		value = value.replace(/[\+\s\(\)\.\-\ ]/g, '');
120
121                //More strict validation can be done in the PHP file.
122		return this.optional(element) || value.length > 5;
123
124	}, $.validator.messages.phone
125	);
126
127	// !Custom validation method
128	$.validator.addMethod('nowhitespace', function (value, element) {
129		// Strip out all spaces, periods, dashes, parentheses, and plus signs
130		return value.indexOf(" ") < 0 && value !== "";
131		;
132	}, $.validator.messages.nowhitespace
133	);
134	$.validator.addMethod('strongPass', function (value, element) {
135		return /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$/g.test(value);
136	}, $.validator.messages.strongPassReq);
137	$.validator.addMethod('passmin8', function (value, element) {
138		return value.length >= 8;
139	}, $.validator.messages.minlength(8));
140	$.validator.addMethod('strongPass-edit', function (value, element) {
141		if (value.length === 0)
142			return true;
143		return /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$/g.test(value);
144	}, $.validator.messages.strongPassReq);
145	$.validator.addMethod('passmin8-edit', function (value, element) {
146		if (value.length === 0)
147			return true;
148		return value.length >= 8;
149	}, $.validator.messages.minlength(8));
150});

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.