Tuesday, 7 July 2015

simple email validation with javascript

<script type="text/javascript">

   function chkform(form)

   {

  re= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (!re.test(form.txtemail.value)) {
    alert('Please provide a valid email address');
    form.txtemail.focus();
    return false;
 }


}
</script>

 <form name="f2" method="post" enctype="multipart/form-data" style=" margin-top: -100px;"  onsubmit="return chkform(this);">

<input type="text" name="txtemail" placeholder="Enter email Addres"/>
</form>

No comments:

Post a Comment