Rai Yawar Ijaz

blog

  Home  |   Contact  |   Syndication    |   Login
  6 Posts | 3 Stories | 16 Comments | 34 Trackbacks

News

Article Categories

Archives

Post Categories

function validateEmail(strEmail)

{

 

             var at="@"

             var dot="."

              var lat=strEmail.indexOf(at)

              var lstr=strEmail.length var

             ldot=strEmail.indexOf(dot)

             if (strEmail.indexOf(at)==-1)

             {

                       alert("Invalid E-mail ID")

                        return false

                }

              if (strEmail.indexOf(at)==-1 || strEmail.indexOf(at)==0 || strEmail.indexOf(at)==lstr)

             {

                 alert("Invalid E-mail ID")

                return false

                }

             if (strEmail.indexOf(dot)==-1 || str.indexOf(dot)==0 || strEmail.indexOf(dot)==lstr)

              {

                       alert("Invalid E-mail ID")

                          return false

                  }

                if (strEmail.indexOf(at,(lat+1))!=-1)

              {

                        alert("Invalid E-mail ID")

                        return false

                  }

             if (strEmail.substring(lat-1,lat)==dot || strEmail.substring(lat+1,lat+2)==dot)

            {

                    alert("Invalid E-mail ID")

                   return false

               }

          if (strEmail.indexOf(dot,(lat+2))==-1)

                    {

                            alert("Invalid E-mail ID")

                             return false

                    }

                if (strEmail.indexOf(" ")!=-1)

         {

                 alert("Invalid E-mail ID")

                   return false

              }

        return true

 }

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Friday, November 12, 2004 2:49 PM

Feedback

# re: How To validate the Email using JavaScript 12/29/2004 6:49 AM meera
<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 ID")
return false
}

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

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

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

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

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

if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}

return true
}

function ValidateForm(){
var emailID=document.frmSample.txtEmail

if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
</script>





<form name="frmSample" method="post" action="#" onSubmit="return ValidateForm()">
<p>Enter an Email Address :
<input type="text" name="txtEmail">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

# re: How To validate the Email using JavaScript 1/20/2005 12:16 PM sd
<a href="">hai</a>

# re: How To validate the Email using JavaScript 3/21/2005 11:02 AM alpa
hello there

# re: How To validate the Email using JavaScript 3/21/2005 11:04 AM alpa
abt the mistake in the script. Try to enter the id as alpa@test.com. which is an invalid id bt still it accepts it. Do let me know any correction thx in advance

# re: How To validate the Email using JavaScript 4/9/2005 6:09 PM serertt
use regular expresions is better

# re: How To validate the Email using JavaScript 4/26/2005 11:39 AM vipin
plz tell me about validation of email


# re: How To validate the Email using JavaScript 6/19/2005 1:29 AM Alf
Very good.

Thanks

:-)

# re: How To validate the Email using JavaScript 7/12/2005 4:11 AM nagraj
how to validate its DNS and SMTP number?

# re: How To validate the Email using JavaScript 8/10/2005 5:45 AM srinivas
thanks for this code to valiadate

# re: How To validate the Email using JavaScript 10/4/2005 3:31 PM kk
Hello and Thanks

# re: How To validate the Email using JavaScript 9/19/2006 10:48 AM Ansh
Hello frns,
i've tried several methods.. but still unable 2 trap in valid e-mails.. any string with a format aaa@aa.aa is acceptable by these codes... is there ne way by which i cn trap the invalid ids..
One more thing cn ne 1 explain how 2 use regular expression 2 validate email ids?

# re: How To validate the Email using JavaScript 5/22/2007 4:39 AM venkat
Hi there, i need to validate multi email-ids seperated with ,(comma).
Thanks in advance

# re: How To validate the Email using JavaScript 2/7/2008 1:10 AM senthil kumar
Hi..
its really fine.. good work...

# re: How To validate the Email using JavaScript 2/14/2010 10:52 AM hary
how can we do the same by using regular expressions????

# re: How To validate the Email using JavaScript 6/10/2010 7:45 AM Deepak
Is this code not too heavy ?i think it is not very good for aspx page.

# re: How To validate the Email using JavaScript 11/13/2010 1:00 AM Pakistani Classified
This is easy way to validate the email.your post is really very helpful.thanks for sharing.

# re: How To validate the Email using JavaScript 7/25/2011 12:58 PM ddddd
xghfv ggjkh kjjhh hfvfdb hjhjjjjjjjj vgdrdty ytdgv

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: