Can't validate form in JS

I can’t validate the forms in this page, when i open it, it just says its a bad age despite everything i write

it should validate all the forms not just one
this is the JS

    const email = document.getElementById('mail');
    const emailError = document.querySelector('#mail + span.error');
    email.addEventListener('input', function (event) {
      if (email.validity.valid) {
        emailError.innerHTML = ''; 
        emailError.className = 'error'; 
      } else {
        showError();
      }
    });
    form.addEventListener('Introducir', function (event) {
      if(!email.validity.valid) {   
        showError();
        event.preventDefault();
      }
    });
    function showError() {
      if(email.validity.valueMissing) {
        emailError.textContent = 'La dirección introducida no es válida.';
      } else if(email.validity.typeMismatch) {
        emailError.textContent = 'Debes introducir una dirección valida.';
      } else if(email.validity.tooShort) {
        emailError.textContent = `El email debe ser como mínimo ${ email.minLength } caracteres de largo; tu has introducido ${ email.value.length }.`;
      }
      emailError.className = 'error';
    }
    if (edad.value < 18) {
            alert("Debes tener 18 o más")
        }
        else{
            formulario.submit()
        } ```

This is the HTML
i had to upload a screenshot because i can't add more code
[The HTML][1]


  [1]: https://i.stack.imgur.com/bXpfS.png

77 thoughts on “Can't validate form in JS”

Leave a Comment