Posts Tagged ‘email validation’

JavaScript to Validate Email Format

To validate the email format,  check the textbox value across the regular expression value. The javascript code and corresponding html code are:

Script :

var efmt=/^\w+((-\w+)(\.\w+))*\@[A-Za-z0-9]+((\.-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;  
 
function checkEmailFormat(field,msg)
{
  var ctrl=document.getElementById(field);
  if((!efmt.test(ctrl.value)) && ctrl.value!=)
  {
    alert(msg);
    ctrl.focus();
  }
}

Add the following code into the Body tag.
Html Code :

<input type=”Text” onblur=”checkEmailFormat(’Txtemail’,'Please enter a valid email address, like sample@yahoo.com’);” id=”Txtemail” >; 

Demo Link

Popularity: 6% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars