$("#login").validate({ rules: { email: { required: true, maxlength: 50, validate_email: true }, password: { required: true, check_password_spaceNotAllow: true, minlength: 3, maxlength: 15 }, }, messages: { email: { required: "Please enter your email." }, password: { required: "Please enter your password.", check_password_spaceNotAllow: "Please enter a valid password." }, }, errorElement: 'span', errorPlacement: function(error, element) { $('.password').css('display','none'); error.addClass('invalid-feedback'); element.closest('.form-group').append(error); }, highlight: function(element, errorClass, validClass) { $(element).parent().addClass('is-invalid'); }, unhighlight: function(element, errorClass, validClass) { $(element).parent().removeClass('is-invalid'); } }) jQuery.validator.addMethod("validate_email", function(value, element) { if (/^([a-zA-Z0-9_\;\.\-\+\@\_\!\@\#\$\%\^\&\*\(\)\=\\\[\]])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value)) { return true; } else { return false; } }, "Please enter a valid email address."); $('body').on('keydown', '.form-control', function() { $('.password').css('display','none'); }) let url = new URL(window.location.href); let params = new URLSearchParams(url.search); if (params.has('s')) { $.notify("Your session is expired", "success"); params.delete('s'); // This will replace the current entry in the browser's history, reloading afterwards // window.location.assign(url.pathname); // This will replace the current entry in the browser's history, reloading afterwards window.history.pushState("", "",url.pathname); } jQuery.validator.addMethod("check_password_spaceNotAllow", function(value) { if (/\s/.test(value)) { return false; } return true; });