1(function ($, window, document, undefined) { 2 'use strict'; 3 4 let pluginName = 'passwordValidator', 5 defaults = { 6 compare: false, 7 validators: [ 8 { 9 regexp: /.{8,}/, 10 message: i18n.translation.Password_Validation_Rules.Minimum_Characters, 11 }, 12 { 13 regexp: /(\p{Ll}+.*\p{Lu})|(\p{Lu}+.*\p{Ll})/u, 14 message: i18n.translation.Password_Validation_Rules.Upper_And_Lowercase, 15 }, 16 { 17 regexp: /\d/, 18 message: i18n.translation.Password_Validation_Rules.Contain_Digit, 19 }, 20 ], 21 }; 22 23 function PasswordValidator (element, options) { 24 this.element = element; 25 this.settings = $.extend({}, defaults, options); 26 this._defaults = defaults; 27 this._name = pluginName; 28 this.init(); 29 } 30 31 $.extend(PasswordValidator.prototype, { 32 init: function () { 33 this.settings.passwordInput.on('input', { self: this }, this.validateEvent); 34 35 if (this.settings.compare) { 36 this.settings.passwordConfirmationInput.on('input', { self: this }, this.validateEvent); 37 } 38 }, 39 40 validateEvent: function (event) { 41 const self = event.data.self; 42 let validCount = self.settings.compare ? -1 : 0; 43 44 $(self.element).empty(); 45 46 $(self.settings.validators).each(function (index, validator) { 47 let isValid = false; 48 49 if (validator.regexp) { 50 isValid = new RegExp(validator.regexp).test(self.settings.passwordInput.val()); 51 } 52 53 let message = document.createElement('li'); 54 message.className = (isValid ? 'text-success' : 'text-danger') + ' list-group-item ' + (self.settings.customClass !== undefined ? self.settings.customClass : ''); 55 message.innerText = `* ${validator.message}`; 56 57 $(self.element).append(message); 58 59 if (isValid) { 60 validCount++; 61 } 62 }); 63 64 if (self.settings.compare) { 65 if (self.settings.passwordInput.val() === $(self.settings.passwordConfirmationInput).val()) { 66 self.passwordMatch = true; 67 validCount++; 68 } else { 69 self.passwordMatch = false; 70 } 71 } 72 73 if (validCount === self.settings.validators.length) { 74 if (self.settings.onValid) { 75 self.settings.onValid(self); 76 } 77 } else { 78 if (self.settings.onInvalid) { 79 self.settings.onInvalid(self); 80 } 81 } 82 }, 83 }); 84 85 $.fn[pluginName] = function (options) { 86 return this.each(function () { 87 if (!$.data(this, 'plugin_' + pluginName)) { 88 $.data(this, 'plugin_' + pluginName, 89 new PasswordValidator(this, options)); 90 } 91 }); 92 }; 93 94})(jQuery, window, document); 95 96 97
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.