Check if a username is free
Ask the server when the user leaves the field.
AJAX · Check if a username is freeBeginner
const user = document.getElementById('username');
user.addEventListener('blur', async function () {
if (!user.value) return;
const res = await fetch('/api/username-free?name=' + encodeURIComponent(user.value));
const data = await res.json();
document.getElementById('hint').textContent = data.ok ? 'Available' : 'Taken';
});fetchvalidationblurform