Validating Email Java Script

Validation

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
    <head>

    <script language = "Javascript">
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail ID00")
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail ID1")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail ID2")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail ID3")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail ID4")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail ID5")
            return false
         }
       
         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID6")
            return false
         }

          return true                   
    }

function validateform(){
    var email=document.frm.email
   
    if ((email.value==null)||(email.value=="")){
        alert("Please Enter your Email ID0")
        email.focus()
        return false
    }
    if (echeck(email.value)==false){
        email.value=""
        email.focus()
        return false
    }
    return true
 }
</script>
    </head>
    <body>
    <form name="frm" method="post" action="/Demo/email.do"  onSubmit="return validateform();">
      <label>
      <h3>Email Id:<input type="text" id="email" name="email"/>
      </h3>
      </label>
 
      <p>
        <label>
        <input type="submit" name="Submit" value="Submit" onselect="return echeck(str);">
        </label>
</p>
    </form>
   
    </body>
</html>


Source
Source
Source

Comments 7 comments

suraj tanwar 5 years ago

good one


best 5 years ago

Really best


Enrique 5 years ago

Really helpful forme


Navneet 5 years ago

great-


Enrique212 5 years ago

Thanks


DAvid 5 years ago

but it didn,t work with me


Anonymous 5 years ago

Awesome dude

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working