Email Validator (On Submit)

Ensure data integrity. This script intercepts the form submission process, checks the email field, and alerts the user if the format is invalid before sending.

Copy the Script

<script>
function checkEmail() {
    var email = document.getElementById('myEmail');
    var filter = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

    if (!filter.test(email.value)) {
        alert('Please provide a valid email address');
        email.focus();
        return false;
    }
    return true;
}
</script>

<form onsubmit="return checkEmail()">
    <input type="text" id="myEmail">
    <button type="submit">Go</button>
</form>

Frequently Asked Questions

The 'Verifier' gives visual feedback while typing. This 'Validator' actually *stops* the form from sending data if there is an error.

Yes, modern browsers verify `type='email'` automatically. This script provides a fallback for older browsers or custom validation logic (e.g., banning free email providers like Gmail/Yahoo).

Yes. You can modify the regex or logic to check if `email.endsWith('@company.com')` to force corporate emails.