// email_validation.js
export function validateEmailLive(inputEl) {
    const emailRE = /^(?=.{2,50}$)[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
    const val = inputEl.value.trim();
    const valid = val === '' || emailRE.test(val);
    const message = valid ? '' : "Email must be in the format: user@example.com.";

    inputEl.classList.toggle('is-invalid', !valid);

    let feedback = inputEl.nextElementSibling;
    if (!feedback || !feedback.classList.contains('invalid-feedback')) {
        feedback = document.createElement('div');
        feedback.className = 'invalid-feedback';
        inputEl.parentNode.insertBefore(feedback, inputEl.nextSibling);
    }

    feedback.textContent = message;
    feedback.style.display = valid ? 'none' : 'block';

    return valid;
}
