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% [?]

Related posts:

  1. set focus on textbox value at the end
  2. Compare two ArrayList in JSP
  3. Set textbox background color when clicked
  4. JSP Custom tags Example
  5. Pagination in JSP
You can leave a response, or trackback from your own site.

Leave a Reply

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