document.getElementById('password-register').addEventListener('input', function () {
const charCount = document.getElementById("password-register").value;
const id = document.getElementById("passwordHelpRegister");
const successID = document.getElementById("passwordHelpSuccess");
if (charCount.length >= 8) {
id.classList.add("d-none");
successID.classList.remove("d-none");
} else {
id.classList.remove("d-none");
successID.classList.add("d-none");
}
});
document.getElementById('username-register').addEventListener('input', function () {
const userName = document.getElementById("username-register").value;
const id = document.getElementById("usernameHelpRegister");
if (/[^a-zA-Z0-9_\-$]/.test(userName)) {
id.innerHTML = 'No special characters or spaces allowed.';
} else {
id.innerHTML = 'Username is a-okay!';
if (userName.length < 3) {
id.innerHTML = 'Username must be at least 3 characters long.';
} else if (userName.length > 25) {
id.innerHTML = 'Username must be 25 characters or less.';
}
else {
fetch('/is_available/' + userName)
.then(res => res.json())
.then(json => {
if (!json[userName]) {
id.innerHTML = 'Username already taken :(';
}
})
}
}
});
document.getElementById('email-register').onfocus = (e) => {
if (e.target.hasAttribute('readonly')) {e.target.removeAttribute('readonly');e.target.blur();e.target.focus()}
};