Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» 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

» Giá của món quà
Fri Apr 13, 2012 6:01 am by Admin

» Sẽ chỉ yêu ai?
Fri Apr 13, 2012 6:01 am by Admin

» Cách đọc bảng chữ cái!
Thu Apr 12, 2012 10:37 pm by Admin

» Gắn trojan, keylog, virus vào website, forum
Tue Apr 10, 2012 1:14 am by Admin

Shopmotion


Affiliates
free forum


kiểm tra email bang JavaScript

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

Back to top


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