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

327
Views
email validation with javascript - if text box is empty i will print a message, how can i use my function to make sure the email is correct?

This is the code i have so far:

i have set up the function to detect the input is a valid email input.

i have set up the code to print an error message when there is no input.

No message is needed if email is correct, only when email is invalid.

"use strict";
function validEmail(email) {
    var re =
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

function validate() {
  var errorMsg = "";
  var emailboxInput = document.getElementById("email");
  var emailbox = emailboxInput.value.trim();
  emailboxInput.value = emailbox;


  if (emailbox === "") {
    errormsg += "Email cannot be empty.<br>";
  }
  if (emailbox === (!validEmail(email))
   {
    }
else {
      errorMessage += "Provide a valid email address<br>";
    }

    else {
      errorMsg += "Provide a valid email address<br>";
    }
  return errorMsg;
}



// submit button
// msg = html area where error messages are displayed
var sendBtn = document.getElementById("form-send");
sendBtn.onclick = function () {
  var msgArea = document.getElementById("msg");
  var msg = validate();
  if (msg === "") {
    return true;
  } else {
    msgArea.innerHTML = msg;
    return false;
  }
};
about 4 years ago · Juan Pablo Isaza
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!