const FORM_VALIDATOR_NOT_REQUIRED = ""; const FORM_VALIDATOR_MUST_BE_FILLED = "must_be_filled"; const FORM_VALIDATOR_MUST_BE_FILLED_WITH_VALID_EMAIL = "must_be_filled_with_valid_email"; const FORM_VALIDATOR_MUST_BE_FILLED_WITH_ONLY_NUMBERS = "must_be_filled_with_only_numbers"; const FORM_VALIDATOR_MUST_BE_VALID_PASSWORD = "must_be_valid_password"; const FORM_VALIDATOR_NEW_PASSWORD_WITH_DOUBLE_INPUT_FIELDS = "new_password_with_double_input_fields"; const FORM_VALIDATOR_MUST_BE_FILLED_WITH_VALID_PASSWORD = "must_be_filled_with_valid_password"; const FORM_VALIDATOR_RECAPTCHA = "recaptcha"; function FormDataClass(form) { this.form = form; this.groups = {}; this.successfulValidation = false; this.setInputElements(); } FormDataClass.prototype.getErrorMessage = function(withHtml) { if(this.groups === undefined || this.successfulValidation) { return ''; } let completeErrorMessage = ''; let errorMessage = ''; let object; for(let key in this.groups) { if(!this.groups.hasOwnProperty(key)) { continue; } object = this.groups[key]; if(object === undefined) { continue; } errorMessage = object.getErrorMessage() if(errorMessage === undefined || errorMessage === '') { continue; } if(completeErrorMessage.length > 0) { completeErrorMessage+= "\n"; } if(withHtml) { completeErrorMessage+='
  • '; } completeErrorMessage+= errorMessage; if(withHtml) { completeErrorMessage+='
  • '; } } return completeErrorMessage; } FormDataClass.prototype.getForm = function() { return this.form; } FormDataClass.prototype.releaseInstances = function () { if(this.groups === undefined) { return ; } let object; for(let key in this.groups) { if(!this.groups.hasOwnProperty(key)) { continue; } object = this.groups[key]; if(object === undefined) { continue; } object.releaseInstances(); } this.groups = {}; } FormDataClass.prototype.setIndicators = function() { if(this.groups === undefined) { return ; } let object; for(let key in this.groups) { if(!this.groups.hasOwnProperty(key)) { continue; } object = this.groups[key]; if(object === undefined) { continue; } object.setIndictor(); if(!object.isSuccessfulValidation()) { this.successfulValidation = false; } } } FormDataClass.prototype.setInputElements = function() { if(this.form === undefined) { return; } let input; let formGroupHandler; let formDataClass = this; this.form.find(":input").each(function(index){ input = new FormInputDataClass($fv(this), formDataClass, index); if(formDataClass.groups[input.group] === undefined) { formDataClass.groups[input.group] = new FormGroupHandler(formDataClass); } formGroupHandler = formDataClass.groups[input.group]; formGroupHandler.addInput(input); //Just add the item if it's a standalone item or it's a group item but not a combined input group item (checkbox / radio / combined selects) }); } FormDataClass.prototype.validateInputs = function() { if(this.groups === undefined) { return ; } let object; this.successfulValidation = true; for(let key in this.groups) { if(!this.groups.hasOwnProperty(key)) { continue; } object = this.groups[key]; if(object === undefined) { continue; } if(!object.validateInput()) { this.successfulValidation = false; } } formValidatorProcessSpecialValidations(); } const FORM_INPUT_SEQUENCE_TYPE_INPUT = 1; const FORM_INPUT_SEQUENCE_TYPE_COMBINED_INPUT = 2; function FormGroupHandler(form) { this.form = form; this.formInputOptionHandler = {}; this.formInputSequence = []; this.objectKeyIndex = 0; this.optionHandlerKey = 0; this.objectKeys = undefined; this.optionHandlerKeys = undefined; BaseHandler.call(this); } FormGroupHandler.prototype = Object.create(BaseHandler.prototype); FormGroupHandler.prototype.constructor = FormGroupHandler; FormGroupHandler.prototype.addInput = function (input) { if(input === undefined) { return; } if(input.isCombinedInput()) { this.addCombinedInput(input); } else { this.addObject(input); } } FormGroupHandler.prototype.addObject = function (object) { BaseHandler.prototype.addObject.call(this, object); this.formInputSequence.push(FORM_INPUT_SEQUENCE_TYPE_INPUT); } FormGroupHandler.prototype.addCombinedInput = function (input) { if(input === undefined || input.combinedInputGroup === undefined) { return; } if(this.formInputOptionHandler[input.combinedInputGroup] === undefined) { this.formInputOptionHandler[input.combinedInputGroup] = new FormInputOptionHandler(this.form); this.formInputSequence.push(FORM_INPUT_SEQUENCE_TYPE_COMBINED_INPUT); } this.formInputOptionHandler[input.combinedInputGroup].addObject(input); } FormGroupHandler.prototype.getInputOrInputOptionHandler = function (key) { if(key === undefined || this.formInputSequence === undefined || this.objects === undefined || this.formInputOptionHandler === undefined) { return undefined; } if(!this.formInputSequence.hasOwnProperty(key)) { return undefined; } let object = this.formInputSequence[key]; if(object === undefined) { return undefined; } let index; if(object === FORM_INPUT_SEQUENCE_TYPE_INPUT) { // noinspection DuplicatedCode it's separate to make the logic easier if(this.objectKeys === undefined || this.objectKeys[this.objectKeyIndex] === undefined || !this.objects.hasOwnProperty(this.objectKeys[this.objectKeyIndex]) || this.objects[this.objectKeys[this.objectKeyIndex]] === undefined) { this.objectKeyIndex++; return undefined; } index = this.objectKeyIndex; this.objectKeyIndex++; return this.objects[this.objectKeys[index]]; } if(object === FORM_INPUT_SEQUENCE_TYPE_COMBINED_INPUT) { // noinspection DuplicatedCode it's separate to make the logic easier if(this.optionHandlerKeys === undefined || this.optionHandlerKeys[this.optionHandlerKey] === undefined || !this.formInputOptionHandler.hasOwnProperty(this.optionHandlerKeys[this.optionHandlerKey]) || this.formInputOptionHandler[this.optionHandlerKeys[this.optionHandlerKey]] === undefined) { this.optionHandlerKey++; return undefined; } index = this.optionHandlerKey; this.optionHandlerKey++; return this.formInputOptionHandler[this.optionHandlerKeys[index]]; } return undefined; } FormGroupHandler.prototype.getErrorMessage = function() { if(this.objects === undefined || this.formInputOptionHandler === undefined || this.formInputSequence === undefined) { return ''; } let successfulValidation = false; let errorMessage = ''; let object; this.objectKeys = Object.keys(this.objects); this.optionHandlerKeys = Object.keys(this.formInputOptionHandler); this.objectKeyIndex = 0; this.optionHandlerKey = 0; for(let key in this.formInputSequence) { // noinspection JSUnfilteredForInLoop the check is done in the function itself object = this.getInputOrInputOptionHandler(key); if(object === undefined) { continue; } if(object instanceof FormInputDataClass) { if(object.successfulValidation) { //Input is successfully validated so the group is fully validated so no need to continue looping successfulValidation = true; break; } } else if(object instanceof FormInputOptionHandler) { if(object.isSuccessfulValidation()) { //InputOptionHandler is successfully validated so the group is fully validated so no need to continue looping successfulValidation = true; break; } } if(errorMessage.length > 0) { errorMessage+= ' of '; } errorMessage+= object.errorMessage; } if(successfulValidation) { return ''; } return errorMessage; } FormGroupHandler.prototype.isSuccessfulValidation = function () { if(this.objects === undefined || this.formInputOptionHandler === undefined || this.formInputSequence === undefined) { return ''; } let object; this.objectKeys = Object.keys(this.objects); this.optionHandlerKeys = Object.keys(this.formInputOptionHandler); this.objectKeyIndex = 0; this.optionHandlerKey = 0; for(let key in this.formInputSequence) { // noinspection JSUnfilteredForInLoop the check is done in the function itself object = this.getInputOrInputOptionHandler(key); if(object === undefined) { continue; } if(object instanceof FormInputDataClass) { if(object.successfulValidation) { //Input is successfully validated so the group is fully validated so no need to continue looping return true; } } else if(object instanceof FormInputOptionHandler) { if(object.isSuccessfulValidation()) { //InputOptionHandler is successfully validated so the group is fully validated so no need to continue looping return true; } } } return false; } FormGroupHandler.prototype.loadItemsFromInput = function (input) { if(input === undefined) { return ; } this.loadItemsWithSelector(":input[group=\""+input.group+"\"]"); } FormGroupHandler.prototype.loadItemsWithSelector = function (selector) { if(selector === undefined) { return ; } let result; if(this.form !== undefined) { result = this.form.find(selector); } else { result = $fv.find(selector); } let object; for(let key in result) { if(!result.hasOwnProperty(key)) { continue; } object = result[key]; if(object === undefined) { continue; } this.addInput(new FormInputDataClass($fv(object), this.form, key)); } } FormGroupHandler.prototype.releaseInstances = function() { let object; this.objectKeys = Object.keys(this.objects); this.optionHandlerKeys = Object.keys(this.formInputOptionHandler); this.objectKeyIndex = 0; this.optionHandlerKey = 0; for(let key in this.formInputSequence) { // noinspection JSUnfilteredForInLoop the check is done in the function itself object = this.getInputOrInputOptionHandler(key); if(object === undefined) { continue; } if(object instanceof FormInputDataClass) { this.removeObject(object); continue; } if(object instanceof FormInputOptionHandler) { object.releaseInstances(); } } this.formInputOptionHandler = {}; this.formInputSequence = []; this.objectKeyIndex = 0; this.optionHandlerKey = 0; this.objectKeys = undefined; this.optionHandlerKeys = undefined; } FormGroupHandler.prototype.setIndictor = function() { if(this.objects === undefined || this.formInputOptionHandler === undefined) { return false; } let object; let successfulValidation = this.isSuccessfulValidation(); for(let key in this.objects) { if(!this.objects.hasOwnProperty(key)) { continue; } object = this.objects[key]; if(object === undefined) { continue; } object.setIndictor(successfulValidation); } for(let key in this.formInputOptionHandler) { if(!this.formInputOptionHandler.hasOwnProperty(key)) { continue; } object = this.formInputOptionHandler[key]; if(object === undefined) { continue; } object.setIndictor(successfulValidation); } } FormGroupHandler.prototype.validateInput = function() { if(this.objects === undefined || this.formInputOptionHandler === undefined || this.formInputSequence === undefined) { return false; } let object; let result = false; this.objectKeys = Object.keys(this.objects); this.optionHandlerKeys = Object.keys(this.formInputOptionHandler); this.objectKeyIndex = 0; this.optionHandlerKey = 0; for(let key in this.formInputSequence) { // noinspection JSUnfilteredForInLoop the check is done in the function itself object = this.getInputOrInputOptionHandler(key); if(object === undefined) { continue; } if(object instanceof FormInputDataClass) { if(object.validateInput()) { result = true; break; } } else if(object instanceof FormInputOptionHandler) { if(object.validateInput()) { result = true; break; } } } return result; } function FormInputOptionHandler(form) { this.form = form; this.errorMessage = ''; BaseHandler.call(this); } FormInputOptionHandler.prototype = Object.create(BaseHandler.prototype); FormInputOptionHandler.prototype.constructor = FormInputOptionHandler; FormInputOptionHandler.prototype.addObject = function (object) { BaseHandler.prototype.addObject.call(this, object); if(object !== undefined && this.errorMessage.length === 0 && object.errorMessage !== undefined) { this.errorMessage = object.errorMessage; } } FormInputOptionHandler.prototype.loadItemsFromInput = function (input) { if(input === undefined) { return ; } let result; let selector = ":input[combined_input_group=\""+input.combinedInputGroup+"\"]"; if(this.form !== undefined) { result = this.form.find(selector); } else { result = $fv.find(selector); } let object; for(let key in result) { if(!result.hasOwnProperty(key)) { continue; } object = result[key]; if(object === undefined) { continue; } this.addObject(new FormInputDataClass($fv(object), this.form, key)); } } FormInputOptionHandler.prototype.isSuccessfulValidation = function() { if(this.objects === undefined) { return true; } let input; for(let key in this.objects) { if(!this.objects.hasOwnProperty(key)) { continue; } input = this.objects[key]; if(input === undefined) { continue; } if(input.successfulValidation) { return true; } } return false; } FormInputOptionHandler.prototype.releaseInstances = function() { if(this.objects !== undefined) { for (let key in this.objects) { if (!this.objects.hasOwnProperty(key)) { continue; } this.removeObject(this.objects[key]); } } this.form = undefined; this.errorMessage = ''; } FormInputOptionHandler.prototype.setIndictor = function(successfulValidation) { if(this.objects === undefined) { return; } let input; for(let key in this.objects) { if(!this.objects.hasOwnProperty(key)) { continue; } input = this.objects[key]; if(input === undefined) { continue; } if(input.isCheckboxOrRadio() && successfulValidation && input.successfulValidation) { /** * When it's a checkbox / radio and the complete input is valid we need to find the one input that was valid. * If not we can't set the correct indicator, because if we use a non valid input, the indicator will be set to required. */ input.setIndictor(successfulValidation) return ; } input.setIndictor(successfulValidation); } if(input !== undefined && input.isCheckboxOrRadio()) { /** * If the input is a checkbox / radio and it reaches here then no input was valid and the last input should handle the indicator */ input.setIndictor(successfulValidation); } } FormInputOptionHandler.prototype.validateInput = function() { if(this.objects === undefined) { return false; } let input; let result = false; for(let key in this.objects) { if(!this.objects.hasOwnProperty(key)) { continue; } input = this.objects[key]; if(input === undefined) { continue; } input = this.objects[key]; result = input.validateInput(); if(!result && !input.isCheckboxOrRadio()) { //It's not a checkbox / radio so all input is required to be filled, if we encounter a false the complete input is not valid and we can return return false; } if(result && input.isCheckboxOrRadio()) { //It's a checkbox / radio so only one input is needed to be valid for the complete input to be valid so we can return here. return true; } } //If it's a checkbox / radio input this will return false, with other inputs this will return true return result; } function FormInputDataClass(jqueryElement, form, index) { this.formValidation = undefined; this.name = undefined; this.group = undefined this.combinedInputGroup = undefined this.defaultGroupGeneration = false this.form = form; this.inputId = undefined; this.successfulValidation = false; this.inputType = undefined; this.errorMessage = ''; this.indicatorIcon = undefined; BaseDataClass.call(this); this.setJqueryElement(jqueryElement, index); } FormInputDataClass.prototype = Object.create(BaseDataClass.prototype); FormInputDataClass.prototype.constructor = FormInputDataClass; FormInputDataClass.prototype.isCheckboxOrRadio = function() { return this.inputType === "radio" || this.inputType === "checkbox"; } FormInputDataClass.prototype.isCombinedInput = function() { return this.combinedInputGroup !== undefined; } FormInputDataClass.prototype.isGroupInput = function() { return this.defaultGroupGeneration === false && this.group !== undefined; } FormInputDataClass.prototype.objectIsBeingRemoved = function() { BaseDataClass.prototype.objectIsBeingRemoved.call(this); this.formValidation = undefined; this.name = undefined; this.group = undefined this.combinedInputGroup = undefined this.defaultGroupGeneration = false this.form = undefined; this.inputId = undefined; this.successfulValidation = false; this.inputType = undefined; this.errorMessage = ''; this.indicatorIcon = undefined; } FormInputDataClass.prototype.setIndictor = function(successfulValidation) { if(this.jqueryElement === undefined || this.formValidation === undefined || this.indicatorIcon === undefined) { return ; } if(successfulValidation) { this.jqueryElement.removeClass(FORM_INPUT_REQUIRED_CSS_CLASS); } else { this.jqueryElement.addClass(FORM_INPUT_REQUIRED_CSS_CLASS); } let input = this; this.jqueryElement.parent().find("span.icon").each(function(){ let inputElement = $fv(this); inputElement.removeClass("icon-input-ok icon-input-nok icon-input-verplicht"); inputElement.addClass(input.indicatorIcon); }); } FormInputDataClass.prototype.setJqueryElement = function(jqueryElement, index) { BaseDataClass.prototype.setJqueryElement.call(this, jqueryElement); if(this.jqueryElement !== undefined) { this.formValidation = this.jqueryElement.attr('form_validation'); this.name = this.jqueryElement.attr('name'); this.group = this.jqueryElement.attr('group'); this.combinedInputGroup = this.jqueryElement.attr('combined_input_group'); this.inputId = this.jqueryElement.attr('id'); this.inputType = this.jqueryElement.attr('type'); this.errorMessage = this.jqueryElement.attr(FORM_ERROR_MESSAGE_ATTRIBUTE_NAME); if(this.errorMessage === undefined) { this.errorMessage = ''; } //Set this to true so the input won't be processed because it's not needed this.successfulValidation = this.formValidation === undefined; if(this.inputId === undefined || this.inputId === '') { this.setId(generateUUID()); } else { this.setId(this.inputId); } if(this.group === undefined) { this.defaultGroupGeneration = true; if(this.combinedInputGroup === undefined) { this.group = "internal_form_validation_group_name_" + index; } else { this.group = this.combinedInputGroup; } } } } FormInputDataClass.prototype.validateInput = function() { this.indicatorIcon = undefined; if(this.successfulValidation || this.formValidation === undefined) { this.indicatorIcon = 'icon-input-ok'; return true; } this.successfulValidation = formValidatorValidateInput(this); if(this.successfulValidation) { this.indicatorIcon = 'icon-input-ok'; } if(this.indicatorIcon === undefined || this.indicatorIcon === '') { this.indicatorIcon = 'icon-input-verplicht'; } return this.successfulValidation; } let $fv = jQuery.noConflict(); const FORM_INPUT_REQUIRED_CSS_CLASS = "verplicht"; const FORM_ERROR_MESSAGE_ATTRIBUTE_NAME = "hiddenplaceholder"; const FORM_EMAIL_REGEX = new RegExp(/^((([a-z]|\d|[!#$%&'*+\-\/=?^_`{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#$%&'*+\-\/=?^_`{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)(((([\x20\x09])*(\x0d\x0a))?([\x20\x09])+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*((([\x20\x09])*(\x0d\x0a))?([\x20\x09])+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); const FORM_NUMBER_REGEX = new RegExp(/^(-)?\d*(\.\d+)?$/); const FORM_PASSWORD_STRENGHT = 20; let formValidatorInterval = undefined; let formValidatorPasswordInputs = undefined; let formValidatorReCaptchaIds = {}; function validateForm(formId, withReturn ,errorMessageHtmlId, withMessage) { if(empty(formId)) { return ; } formValidatorPasswordInputs = []; let form = new FormDataClass($fv('#'+formId)); form.validateInputs(); form.setIndicators(); if(!form.successfulValidation && withMessage) { let errorMessage = form.getErrorMessage(errorMessageHtmlId !== undefined && errorMessageHtmlId !== ''); if(errorMessageHtmlId !== undefined && errorMessageHtmlId !== '') { let errorMessageElement = $fv("."+errorMessageHtmlId); errorMessageElement.css({display:"block"}) errorMessageElement.find(".foutmeldingvergeten").html(""); } else { alert(errorMessage); } } form.releaseInstances(); formValidatorPasswordInputs = []; if(withReturn) { form.form = undefined; return form.successfulValidation; } if(form.successfulValidation) { form.form.submit(); form.form = undefined; } } function formValidatorCheckFormInputOnBlur(inputElement) { if(inputElement === undefined) { return ; } formValidatorClearFormValidatorTimeOut(); formValidatorPasswordInputs = []; let input = new FormInputDataClass($fv(inputElement), undefined, 0); // noinspection JSUnresolvedVariable variables come from PHP if(input.formValidation === FORM_VALIDATOR_NEW_PASSWORD_WITH_DOUBLE_INPUT_FIELDS) { //new Passwords is a special situation it can't be handled via a class at this moment $fv(":input[form_validation=\""+input.formValidation+"\"]").each(function (){ let input = new FormInputDataClass($fv(this), undefined, 0); input.setIndictor(input.validateInput()); //input.releaseInstances(); }) formValidatorProcessSpecialValidations(); let object; for(let key in formValidatorPasswordInputs) { // noinspection JSUnfilteredForInLoop the check is done in the function itself object = formValidatorPasswordInputs[key]; if(object === undefined) { continue; } object.objectIsBeingRemoved(); } formValidatorPasswordInputs = []; return ; } if(formValidatorCheckFormInputOnBlurCustom(inputElement)) { formValidatorProcessSpecialValidations(); return; } if(input.isGroupInput()) { let groupHandler = new FormGroupHandler(); groupHandler.loadItemsFromInput(input); groupHandler.validateInput(); formValidatorProcessSpecialValidations(); groupHandler.setIndictor(); groupHandler.releaseInstances(); return ; } if(input.isCombinedInput()) { let inputOptionHandler = new FormInputOptionHandler(); inputOptionHandler.loadItemsFromInput(input); inputOptionHandler.validateInput(); formValidatorProcessSpecialValidations(); inputOptionHandler.setIndictor(); inputOptionHandler.releaseInstances(); return ; } let result = input.validateInput(); formValidatorProcessSpecialValidations(); input.setIndictor(result); input.objectIsBeingRemoved(); } // noinspection JSUnusedLocalSymbols inputElement might be used by custom implementations function formValidatorCheckFormInputOnBlurCustom(inputElement) { return false;//return true if the it's been handled by a custom implementation } function formValidatorCheckFormInputAfterInterval(inputElement) { if(inputElement === undefined) { return ; } formValidatorClearFormValidatorTimeOut(); formValidatorInterval = setTimeout(function(){formValidatorCheckFormInputOnBlur(inputElement);}, 375); } function formValidatorCheckPasswordInputs() { if(formValidatorPasswordInputs === undefined) { return; } let passwordInput = undefined; let firstPasswordInput = undefined; for(let key in formValidatorPasswordInputs) { if(!formValidatorPasswordInputs.hasOwnProperty(key)) { continue; } passwordInput = formValidatorPasswordInputs[key]; if(passwordInput === undefined) { continue; } if(!passwordInput.successfulValidation) { //If it's not successfully validated, no point in checking the rest of the validation. continue; } if(firstPasswordInput === undefined) { if(passwordInput.jqueryElement === undefined) { passwordInput.successfulValidation = false; passwordInput.indicatorIcon = 'icon-input-nok'; passwordInput.setIndictor(passwordInput.successfulValidation); continue; } firstPasswordInput = passwordInput; continue; } if(passwordInput.jqueryElement === undefined) { passwordInput.successfulValidation = false; passwordInput.indicatorIcon = 'icon-input-nok'; passwordInput.setIndictor(passwordInput.successfulValidation); continue; } if(firstPasswordInput.jqueryElement.val() !== passwordInput.jqueryElement.val()) { passwordInput.successfulValidation = false; passwordInput.indicatorIcon = 'icon-input-nok'; passwordInput.errorMessage += ' - Wachtwoorden komen niet overeen'; passwordInput.setIndictor(passwordInput.successfulValidation); } } } function formValidatorClearFormValidatorTimeOut() { if(formValidatorInterval !== undefined) { clearTimeout(formValidatorInterval); } } function formValidatorisValueValidEmailAddress(value) { if(value === undefined || value === '') { return false; } return FORM_EMAIL_REGEX.test(value); } function formValidatorMustBeFilled(input) { if (input === undefined || input.jqueryElement === undefined) { return false; } let value = input.jqueryElement.val(); if(value !== undefined && value !== '') { return true; } input.indicatorIcon = 'icon-input-verplicht'; return false; } function formValidatorMustBeFilledWithOnlyNumbers(input) { if (input === undefined || input.jqueryElement === undefined) { return false; } let value = input.jqueryElement.val(); if(value === undefined || value === '') { input.indicatorIcon = 'icon-input-verplicht'; return false; } if(FORM_NUMBER_REGEX.test(value)) { return true; } input.indicatorIcon = 'icon-input-nok'; return false; } function formValidatorMustBeFilledWithValidEmail(input) { if (input === undefined || input.jqueryElement === undefined) { return false; } let value = input.jqueryElement.val(); if(value === undefined || value === '') { input.indicatorIcon = 'icon-input-verplicht'; return false; } if(formValidatorisValueValidEmailAddress(value)) { return true; } input.indicatorIcon = 'icon-input-nok'; return false; } function formValidatorMustBeFilledWithValidPassword(input) { if (input === undefined || input.jqueryElement === undefined) { return false; } let value = input.jqueryElement.val(); if(value === undefined || value === '') { input.indicatorIcon = 'icon-input-verplicht'; return false; } if(checkPasswordStrength(value) > FORM_PASSWORD_STRENGHT) { return true; } input.indicatorIcon = 'icon-input-nok'; input.errorMessage += ' - Wachtwoord is niet sterk genoeg'; return false; } function formValidatorNewPasswordWithDoubleInputFields(input) { if (input === undefined || input.jqueryElement === undefined) { return false; } if(formValidatorPasswordInputs !== undefined) { formValidatorPasswordInputs.push(input); } return formValidatorMustBeFilledWithValidPassword(input); } function formValidatorMustBeValidPassword(input) { if (input === undefined || input.jqueryElement === undefined) { return false; } let value = input.jqueryElement.val(); if(value === undefined || value === '' || checkPasswordStrength(value) > FORM_PASSWORD_STRENGHT) { return true; } input.indicatorIcon = 'icon-input-nok'; input.errorMessage += ' - Wachtwoord is niet sterk genoeg'; return false; } function formValidatorProcessSpecialCustomValidations() { } function formValidatorProcessSpecialValidations() { formValidatorProcessSpecialCustomValidations(); if(formValidatorPasswordInputs !== undefined) { formValidatorCheckPasswordInputs(); } } function formValidatorReCaptcha(input) { // noinspection JSUnresolvedVariable grecaptcha probably set by Google ReCaptcha? if(input === undefined || input.jqueryElement === undefined || typeof grecaptcha === 'undefined' || formValidatorReCaptchaIds === undefined) { return false; } let recaptchaId = input.jqueryElement.attr('id'); try { // noinspection JSUnresolvedVariable,JSUnresolvedFunction grecaptcha / getResponse probably set by Google ReCaptcha? if (formValidatorReCaptchaIds.hasOwnProperty(recaptchaId) && !grecaptcha.getResponse(formValidatorReCaptchaIds[recaptchaId])) { input.errorMessage = input.jqueryElement.data('captcha_error_message'); // noinspection JSUnresolvedVariable grecaptcha probably set by Google ReCaptcha? grecaptcha.reset(formValidatorReCaptchaIds[recaptchaId]); return false; } } catch (e) { return false; } return true; } function formValidatorValidateCheckboxOrRadio(input) { if(input === undefined || input.jqueryElement === undefined) { return false; } return input.jqueryElement.is(":checked"); } // noinspection JSUnusedLocalSymbols input might be used by custom implementations function formValidatorValidateCustomValidation(input) { return false; } function formValidatorValidateInput(input) { if (input === undefined) { return false; } if (input.formValidation === undefined || input.formValidation === '') { return true; } // noinspection JSUnresolvedVariable variables come from PHP switch (input.formValidation) { case FORM_VALIDATOR_NOT_REQUIRED: return true; case FORM_VALIDATOR_MUST_BE_FILLED: if (input.isCheckboxOrRadio()) { return formValidatorValidateCheckboxOrRadio(input); } return formValidatorMustBeFilled(input); case FORM_VALIDATOR_MUST_BE_FILLED_WITH_VALID_EMAIL: return formValidatorMustBeFilledWithValidEmail(input); case FORM_VALIDATOR_MUST_BE_FILLED_WITH_ONLY_NUMBERS: return formValidatorMustBeFilledWithOnlyNumbers(input); case FORM_VALIDATOR_MUST_BE_VALID_PASSWORD: return formValidatorMustBeValidPassword(input); case FORM_VALIDATOR_NEW_PASSWORD_WITH_DOUBLE_INPUT_FIELDS: return formValidatorNewPasswordWithDoubleInputFields(input); case FORM_VALIDATOR_MUST_BE_FILLED_WITH_VALID_PASSWORD: return formValidatorMustBeFilledWithValidPassword(input); case FORM_VALIDATOR_RECAPTCHA: return formValidatorReCaptcha(input); default: return formValidatorValidateCustomValidation(input); } } function checkPasswordStrength(wachtwoord) { let strength = 0; let numberOfRegMatches; //Punten voor kleine letters strength+= getNumberOfRegMatchesInString(wachtwoord, /[a-zA-Z]/g); //Punten voor cijfers strength+= getNumberOfRegMatchesInString(wachtwoord, /[0-9]/g, 4)*2; //Punten voor speciale tekens numberOfRegMatches = getNumberOfRegMatchesInString(wachtwoord, /[!@#$%^&*?_~=+-]/g, 4); if(numberOfRegMatches > 0) { strength+= numberOfRegMatches*2; } //Punten voor combinaties numberOfRegMatches = getNumberOfRegMatchesInString(wachtwoord, /([a-z]+?[A-Z])|([A-Z]+?[a-z])/g, 4); if(numberOfRegMatches > 0) { strength+= numberOfRegMatches*4; } //Punten voor combinaties numberOfRegMatches = getNumberOfRegMatchesInString(wachtwoord, /([a-zA-Z]+?[0-9])|([0-9]+?[a-zA-Z])/g, 4); if(numberOfRegMatches > 0) { strength+= numberOfRegMatches*4; } //Punten voor combinaties numberOfRegMatches = getNumberOfRegMatchesInString(wachtwoord, /([a-zA-Z0-9]+?[!@#$%^&*?_~=+-])|([!@#$%^&*?_~=+-]+?[a-zA-Z0-9])/g, 4); if(numberOfRegMatches > 0) { strength+= numberOfRegMatches*4; } if (strength<0) { strength=0; } if (strength>40) { strength=40; } return strength; } function setReCaptchas() { $fv(document).ready(function() { $fv('input[id^="recaptcha-"]').each(function() { let element = $fv(this); let id = element.attr('id'); // noinspection JSUnresolvedVariable grecaptcha probably set by Google ReCaptcha? formValidatorReCaptchaIds[id] = grecaptcha.render(id+'-container', { "sitekey" : element.attr('data-sitekey'), "theme" : element.attr('data-theme'), "badge" : element.attr('data-badge-position'), "size" : 'invisible' }); executeReCaptcha(id); setInterval(function(){ executeReCaptcha(id); }, 60000 ); // Get new token every minute }); }); } function executeReCaptcha(id) { // noinspection JSUnresolvedVariable grecaptcha probably set by Google ReCaptcha? grecaptcha.execute() .then(function(token) { // Verify the token on the server. $fv('#'+id).val(token); }); }