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

153
Views
Validate email field not empty Javascript

I'm trying to make validate if an email form field is not empty, of course I'm learning by making mistakes, but some explanation is needed from any of You Pro guys.

Heres wat I have and it's not working, all do it looks logical to me.

<script>
  document.getElementById('regform').addEventListener("submit", function(e))
{
    if(document.querySelector("#mail")=='')
   {
      e.alert("You need to provide a valid email");
    } 
});
</script>

I'm kind of confused here.

This is the HTML:

<form class="login_form" id="regform" action="" method="post">
  <input type="email" name="mail" id="mail" placeholder="Your @ email" required>
  <input type="submit" value="INGRESAR">
</form>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

<script>
 document.getElementById('regform').addEventListener("submit", function(e))
 {
     if(document.querySelector("#mail").value == '')
     {
          e.alert("You need to provide a valid email");
     } 
}
</script>

get value from input text using document.querySelector("#mail").value anddocument.querySelector("#mail") only get element

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!