Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» NewBlueFx TotalFX Windows-FL | 1.11 GB
Tue Dec 17, 2013 12:42 pm by titquarra

» NewBlueFx TotalFX Windows-FL | 1.11 GB
Tue Dec 17, 2013 12:42 pm by titquarra

» Celebrity.Sex.Tape.UNCUT.&.UNRATED.2012.720p.BRrip.x264.YIFY.mp4
Tue Dec 17, 2013 8:32 am by titquarra

» Maya Autodesk Personal Learning Edition 8.5
Tue Dec 17, 2013 7:47 am by titquarra

» Tuyệt Kỹ Đong Giai Chân Kinh (tuyệt Kỹ cua trai)
Thu Aug 23, 2012 5:38 am by Admin

» Tuyệt kỹ cua giai
Thu Aug 23, 2012 5:36 am by Admin

» NETCAT.........
Mon Aug 13, 2012 6:35 am by Admin

» Bảo mật CSDL bằng phương pháp mã hóa.
Tue Apr 17, 2012 10:04 pm by Admin

» Hàm mã hóa MD5 bằng JavaScript
Tue Apr 17, 2012 10:03 pm by Admin

Shopmotion


Affiliates
free forum


kiểm tra email bang JavaScript

View previous topic View next topic Go down

kiểm tra email bang JavaScript

Post  chipid1989 on Tue May 10, 2011 10:31 am

Code:
<HTML>
<HEAD>
<TITLE>check valid email</TITLE>
</HEAD>
<BODY bgcolor="#E0F8F7">

<script language = "Javascript">   
  /* This is code to check valid email using java script. */   
  function emailCheck(str) {       
      var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)

    // check if '@' is at the first position or
            at last position or absent in given email
        if (str.indexOf(at)==-1 || str.indexOf(at)==0 ||
                str.indexOf(at)==lstr){
          alert("Invalid E-mail ID")
          return false
        }           
 
    // check if '.' is at the first position or at last
        position or absent in given email
        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 ||
                str.indexOf(dot)==lstr){
            alert("Invalid E-mail ID")
            return false
        }     
     
    // check if '@' is used more than one times in given email
        if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail ID")
            return false
        }
                 
    // check for the position of '.'
        if (str.substring(lat-1,lat)==dot ||
                str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail ID")
            return false
        }         

    // check if '.' is present after two characters
        from location of '@'
        if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail ID")
            return false
        }
                     
    // check for blank spaces in given email
        if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID")
            return false
        }   
            return true                   
    }     
 function ValidateForm(){
    var emailID=document.form.txtEmail
                 
  //check if email is not entered or only spaces
      are entereds in appropriate textbox
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID")
                     
  // set cursor to the textbox provided for email entry
        emailID.focus()
        return false
    }

    if (emailCheck(emailID.value)==false){
        emailID.value=""
        emailID.focus()
        return false
    }          return true
 }

</script>
    <form name="form" method="post" onSubmit="return ValidateForm()">
      <p>Enter an Email Address <input type="text" name="txtEmail"></p>
      <p> <input type="submit" name="Submit" value="Submit"></p>
    </form>
</BODY>
</HTML>

chipid1989

Tổng số bài gửi : 15
Join date : 2011-04-15

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum