function checkUsername() { var username = document.getElementById("username").value; var requirements = document.getElementById("username-requirements"); var len3 = username.length >= 3; var nosymbol = username.match(/["'<>/&:;\\|{}[\]()]/) == null; var nospace = username.match(/[ ]/) == null; requirements.classList[len3 ? "add" : "remove"]("len-3"); requirements.classList[nosymbol ? "add" : "remove"]("nosymbol"); requirements.classList[nospace ? "add" : "remove"]("nospace"); requirements.parentElement.classList.remove("all"); if (!len3) return false; if (!nosymbol) return false; if (!nospace) return false; requirements.parentElement.classList.add("all"); return true; } function checkEmail() { var email = document.getElementById("email").value; var requirements = document.getElementById("email-requirements"); // e-mail addresses can really only be verified by attempting to send a mail // to them, so this is pretty much useless for client-side anyways var valid = email.match(/.+?@.+/) != null; requirements.classList[valid ? "add" : "remove"]("valid"); requirements.parentElement.classList.remove("all"); if (!valid) return false; requirements.parentElement.classList.add("all"); return true; } function checkPassword() { var password = document.getElementById("password").value; var requirements = document.getElementById("password-requirements"); var len8 = password.length >= 8; var minnum2 = password.match(/[0-9]/g)?.length >= 2; var minsym2 = password.match(/[!@#$%^&*()\-=_+[\]{}\\|;:'",<.>/?`~]/g)?.length >= 2; var uppercase = password.match(/[A-Z]/) != null; var lowercase = password.match(/[a-z]/) != null; requirements.classList[len8 ? "add" : "remove"]("len-8"); requirements.classList[minnum2 ? "add" : "remove"]("digit-2"); requirements.classList[minsym2 ? "add" : "remove"]("symbol-2"); requirements.classList[uppercase ? "add" : "remove"]("has-uppercase"); requirements.classList[lowercase ? "add" : "remove"]("has-lowercase"); requirements.parentElement.classList.remove("all"); if (!len8) return false; if (!minnum2) return false; if (!minsym2) return false; if (!uppercase) return false; if (!lowercase) return false; requirements.parentElement.classList.add("all"); return true; } function checkAllFields() { var username = checkUsername(); var email = checkEmail(); var password = checkPassword(); if (!username) return false; if (!email) return false; if (!password) return false; return true; } function updateRegisterButton() { document.getElementById("register-submit").disabled = !checkAllFields(); } // update when fields are changed document.getElementById("username").addEventListener("input", updateRegisterButton); document.getElementById("email").addEventListener("input", updateRegisterButton); document.getElementById("password").addEventListener("input", updateRegisterButton); updateRegisterButton();