Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
¿Cómo mostrar un mensaje de error cuando la entrada no coincide con Regex?

Simplemente quiero mostrar un mensaje de error como "El correo electrónico debe contener @" y evitar que se envíe el formulario, si hay un error.

¿Cómo puedo hacer esto?

Mi último intento que es un fracaso:

 const email = document.getElementById('email') const emailmessage = document.getElementById('emailmessage') const regex = ('^\S+@\S+$') form.addEventListener('submit', function (event) { if(!email.value.match(regex)) { emailchecker(); event.preventDefault(); } }); let emailchecker = function() { if(!email.value.match(regex)) { document.getElementById('emailmessage').innerHTML = '<img src="222.svg" height="15"/> Email Error'; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su código es correcto, solo necesita la expresión regular para la validación del correo electrónico:

 function emailchecker (emailAdress){ let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; if (emailAdress.match(regexEmail)) { return true; } else { return false; } } let emailAdress = "test@gmail.com"; console.log(emailchecker(emailAdress)); //return true
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!