Check email id validation

Here is a simple email ID validation function in JavaScript:

function validateEmail(email) {
    var emailReg = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    if(emailReg.test(email)) {
        return true;
    } else {
        return false;
    }
}

// Example usage:
var email = "[email protected]";
if(validateEmail(email)) {
    console.log("Email is valid");
} else {
    console.log("Email is not valid");
}

This function uses a regular expression to check if the email ID is in the correct format. The regular expression used here is a common one for email validation, but it's not foolproof and may not match all valid email addresses.

Here's a breakdown of how the regular expression works:

If the email ID matches this regular expression, the function returns true, otherwise it returns false.