ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Internet & the Web

Validating Email Java Script

Updated on April 20, 2013

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

    0 of 8192 characters used
    Post Comment

    • profile image

      Anonymous 6 years ago

      Awesome dude

    • profile image

      DAvid 6 years ago

      but it didn,t work with me

    • profile image

      Enrique212 6 years ago

      Thanks

    • profile image

      Navneet 6 years ago

      great-

    • profile image

      Enrique 6 years ago

      Really helpful forme

    • profile image

      best 6 years ago

      Really best

    • profile image

      suraj tanwar 6 years ago

      good one