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

163
Views
Email Validation using setCustomValidity

I got the following code for

// Validating Email

function validateEmail() {
    var mail = document.getElementById("email").value;
    var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{3})+$/;
    var endEmail = "@gmail"
    if(mail.match(mailformat) && (mail.charAt(x.length-1) == endEmail) ) {
mail.value += ".com"
        alert(mail)
        return true;
    
} else if (email.validity.valueMissing) {
        console.log("Email is missing")
        email.setCustomValidity("Please fill in the email.");
    } 
}

I have a problem with checking the email. The logic I am trying to implement is to check whether the email contains “gmail” after “@” and to validate the email ends in “.com” (This check is only mandatory if the email field has “gmail” after “@”.). In the case of gmail being in the email after “@” and the ending being something other than “.com”, I wanna fix this for the user and let the submission go through after the fix.

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!