PageSourceSearch

https://www.renfrewshiregolfunion.co.uk/js/form-validation.js

js renfrewshiregolfunion.co.uk collected 2026-09-27 15:22:21 UTC 10,270 bytes, 305 lines download raw bytes

1// Required field validation
2
3var errorclass = "has-error";
4
5function validateForm(formclass) {
6    var errors = 0;
7
8    $(formclass).find(".form-group.required input[type=text]").each(function () {
9        var isDisabled = $(this).closest(".disabled");
10        if (isDisabled.length > 0) return;
11
12        if ($(this).val().trim() == "") {
13            $(this).parent().addClass(errorclass);
14            errors = errors + 1;
15        }
16    });
17
18    $(formclass).find(".form-group.required input[type=password]").each(function () {
19        if ($(this).val().trim() == "") {
20            $(this).parent().addClass(errorclass);
21            errors = errors + 1;
22        }
23    });
24
25    $(formclass).find(".form-group.required textarea").each(function () {
26        if ($(this).val().trim() == "") {
27            $(this).parent().addClass(errorclass);
28            errors = errors + 1;
29        }
30    });
31
32    $(formclass).find("input.numeric").each(function () {
33        if (($(this).val().trim() != "") && !$.isNumeric($(this).val().trim())) {
34            $(this).parent().addClass(errorclass);
35            errors = errors + 1;
36        }
37    });
38
39    $(formclass).find("input.email").each(function () {
40        if (!IsEmail($(this).val().trim())) {
41            $(this).parent().addClass(errorclass);
42            errors = errors + 1;
43        }
44    });
45
46    $("body > .div-eng").find(formclass).find("input.post-code-validate").each(function () {    
47        if (!IsUKPostCode($(this).val().trim())) {
48            $(this).parent().addClass(errorclass);
49            errors = errors + 1;
50        }
51    });
52
53    $(formclass).find("input.post-code-validate-v2").each(function () {
54        var regEx = $(this).attr('data-regex').replace(/^\/|\/$/g, "");
55        var minLength = Number($(this).attr('data-min'));
56        var maxLength = Number($(this).attr('data-max'));
57        var postCode = $(this).val().trim();
58        if (!validatePostcode(regEx, minLength, maxLength, postCode)) {
59            $(this).parent().addClass(errorclass);
60            errors = errors + 1;
61        }
62    });
63
64    $(formclass).find(".form-group.required select").each(function () {
65        if ($(this).val() == "Select") {
66            $(this).parent().addClass(errorclass);
67            errors = errors + 1;
68        }
69    });
70
71    $(formclass).find(".birthday-picker.required select").each(function () {
72        if ($(this).val() == "0") {
73            $(this).parent().addClass(errorclass);
74            errors = errors + 1;
75        }
76    });
77
78    $(formclass).find(".form-group.required input[type=checkbox]").each(function () {
79        if ($(this).prop('checked') == false) {
80            $(this).parent().parent().addClass('checkbox');
81            $(this).closest('.form-group').addClass(errorclass);
82            errors = errors + 1;
83        }
84    });
85
86    $(formclass).find(".form-group.onerequiredcheck").each(function () {
87        var atLeastOneIsChecked = $(this).find('input:checkbox').is(':checked');
88        if (!atLeastOneIsChecked) {
89            $(this).closest('.form-group').addClass(errorclass);
90            errors = errors + 1;
91        }
92    });
93
94    // required checkbox custom text
95    $(formclass).find(".form-check.required input[type=text]").each(function () {
96        if ($(this).val().trim() == "") {
97            $(this).addClass(errorclass);
98            errors = errors + 1;
99        }
100    });
101
102    $(formclass).find(".form-group.onerequiredradio").each(function () {
103        var isDisabled = $(this).closest(".disabled");
104        if (isDisabled.length > 0) return;
105
106        var atLeastOneIsSelected = $(this).find('input:radio').is(':checked');
107        if (!atLeastOneIsSelected) {
108            $(this).closest('.form-group').addClass(errorclass);
109            errors = errors + 1;
110        }
111    });
112
113    var emailinputs = $(".confirm-email");
114    var emailvalue;
115
116    for (var i = 0; i < emailinputs.length; i++) {
117        if (i > 0 && (emailvalue != $(emailinputs[i]).find('.form-control').val())) {
118            $(".confirm-email").addClass(errorclass);
119            errors = errors + 1;
120        }
121        emailvalue = $(emailinputs[i]).find('.form-control').val();
122    }
123
124    var passwordinputs = $(".confirm-password");
125    var passwordvalue;
126
127    for (var i = 0; i < passwordinputs.length; i++) {
128        if (i > 0 && (passwordvalue != $(passwordinputs[i]).find('.form-control').val())) {
129            $(".confirm-password").addClass(errorclass);
130            errors = errors + 1;
131        }
132        passwordvalue = $(passwordinputs[i]).find('.form-control').val();
133    }
134
135    var hasEmailCommunationRadiolist = false;
136    $('.email-communication-radio:not([novalidate])').each(function () {
137        hasEmailCommunationRadiolist = true;
138
139        var $radioGroup = $(this);
140        var name = $radioGroup.find('input[type="radio"]').attr('name');
141        var isChecked = $(`input[name="${name}"]:checked`).length > 0;
142
143        if (!isChecked) {
144            $radioGroup.addClass(errorclass);
145            errors = errors + 1;
146        } else {
147            $radioGroup.removeClass(errorclass);
148        }
149    });
150
151    if (errors > 0 || HasValidationErrors() == true) {
152        $(formclass).find('.jsvalidation-message').show();
153        BindEvents();
154        return false;
155    } else {
156        return true;
157    }
158}
159
160function IsEmail(email) {
161    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
162    return regex.test(email);
163}
164
165function IsNumberLetterSpaceKey(evt) {
166    var charCode = (evt.which) ? evt.which : evt.keyCode;    
167    if (charCode == 32 || (charCode > 47 && charCode < 58) || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
168        return true;
169    return false;
170}
171
172function IsUKPostCode(postCode) {
173    var regex = /^[0-9a-zA-Z\s]+$/;
174    if (regex.test(postCode)) {
175        if (postCode.length >= 2 && postCode.replace(' ', '').length <= 7) {
176            return true;
177        } else {
178            return false;
179        }
180    } else { return false; }
181}
182
183function validatePostcode(regex, minLength, maxLength, postCode) {
184    var regex = new RegExp(regex);
185    var postCodeLength = postCode.replace(/\s/g, "").length;
186
187    return regex.test(postCode) &&
188        postCodeLength >= minLength &&
189        postCodeLength <= maxLength;
190}
191
192function IsNumberKey(evt) {
193    var charCode = (evt.which) ? evt.which : evt.keyCode;
194    if (charCode > 31 && (charCode < 48 || charCode > 57))
195        return false;
196    return true;
197}
198
199$(document).ready(function () {
200    BindEvents();
201});
202
203function BindEvents() {
204    $(".form-group.required input[type=text],.form-group.required input[type=email],.form-group.required input[type=password],.form-group.required select,.form-group.required textarea").each(function () {
205        $(this).focus(function () {
206            $(this).parent().removeClass(errorclass);
207        });
208        $(this).blur(function () {
209            if (this.value == "" || this.value == "Select" || this.value == "0") {
210                $(this).parent().addClass(errorclass);
211            }
212        });
213    });
214
215    // required checkbox custom text
216    $(".form-check.required input[type=text]").each(function () {
217        $(this).focus(function () {
218            $(this).removeClass(errorclass);
219        });
220        $(this).blur(function () {
221            if (this.value == "") {
222                $(this).addClass(errorclass);
223            }
224        });
225    });
226
227    $(".form-group-dob select").each(function () {
228        $(this).change(function () {
229            var isComplete = IsDateComplete(this);
230            if (isComplete) {
231                $(this).parent().parent().parent().removeClass(errorclass);
232            }
233            else {
234                $(this).parent().parent().parent().addClass(errorclass);
235            }
236        });
237    });
238
239    $(".form-group.onerequiredradio input[type=radio]").each(function () {
240        $(this).change(function () {
241            $(this).closest('.form-group.onerequiredradio').removeClass(errorclass);
242            $(this).parent().removeClass(errorclass);
243            $(this).parent().parent().removeClass(errorclass);
244            $(this).parent().parent().parent().removeClass(errorclass);
245            $(this).parent().parent().parent().parent().removeClass(errorclass);
246        });
247    });
248
249    // For the checkboxes
250    $(".form-group.required input[type=checkbox]").each(function () {
251        $(this).change(function () {
252            $(this).parent().removeClass(errorclass);
253            $(this).parent().parent().removeClass(errorclass);
254            $(this).parent().parent().parent().removeClass(errorclass);
255            $(this).parent().parent().parent().parent().removeClass(errorclass);
256        });
257
258        $(this).blur(function () {
259            if ($(this).prop('checked') == false) {
260                $(this).parent().addClass(errorclass);
261            }
262        });
263    });
264
265    $(".form-group.onerequiredcheck input[type=checkbox]").each(function () {
266        $(this).change(function () {
267            if ($(this).prop('checked') == true) {
268                $(this).parent().parent().parent().removeClass(errorclass);
269            }
270            else {
271                IsAtLeastOneIsChecked();
272            }
273        });
274        
275    });
276}
277
278function IsAtLeastOneIsChecked() {
279    $(".form-group.onerequiredcheck").each(function () {
280        var atLeastOneIsChecked = $(this).find('input:checkbox').is(':checked');
281        if (!atLeastOneIsChecked) {
282            $(this).closest('.form-group').addClass(errorclass);
283        }
284        else {
285            $(this).closest('.form-group').removeClass(errorclass);
286        }
287    });
288}
289
290function IsDateComplete(select) {
291    var isComplete = true;
292    $(select).parent().find("select").each(function () {
293        if ($(this).val() == "0") {
294            isComplete = false;
295        }
296    });
297    return isComplete;
298}
299
300function HasValidationErrors() {
301    if ($('.has-error').length) {
302        return true;
303    }
304    return false;
305}

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.