JavaScript Validation of Form Fields: Email Address

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns=””>


<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title>JavaScript Email Address Validation</title>


function ValidateEmail(form) {

// check for invalid email address format

if (/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test({

// if no invalid characters then pass validation

alert(“The email address you have entered has been validated successfully”)

return (true)


// if invalid characters then fail validation

alert(“The email address you have entered is invalid, please use ‘'”)

return (false)



<style type=”text/css”>


.style1 {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: small;

font-weight: bold;






<br /><br />

<form onSubmit=”return ValidateEmail(this)” action=””>

<table border=”0″ cellspacing=”0″ cellpadding=”5″ style=”margin: auto;”>


<td><span class=”style1″>Enter Email Address:</span> </td>

<td><input type=”text” name=”email” /></td>

<td><input type=”submit” value=”Validate” /></td>






Validated by W3C (2010) Markup Validation Service


W3C (2010) Markup Validation Service [Online]. Available at (Accessed 5 September 2010).