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.