E-mail Validation

This snippet will validate that a properly formatted E-mail address is entered in a form. It will not validate if the E-mail address is real, there is no way to check for that with JavaScript.

Html

<form onSubmit="return validateEmail(this);" action="">
    E-mail Address:
    <input type="text" name="emailid" />
    <input type="submit" value="Submit" />
    <input type="reset" value="Reset" />
</form>

Javascript

<script type="text/javascript">
function validateEmail(theForm) { if (/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(theForm.email - id.value)) { return (true); } alert("Invalid e-mail address! Please enter again carefully!."); return (false); }
</script>

Categories


Snippet Coding Tools