» Để có thể tham gia thảo luận, các bạn phải đăng ký làm thành viên, click vào đây để đăng ký.
» Mong bạn sẽ có nhưng giây phút bổ ích trên 4rum.
» Cảm ơn sự ủng hộ của bạn.

Join the forum, it's quick and easy

» Để có thể tham gia thảo luận, các bạn phải đăng ký làm thành viên, click vào đây để đăng ký.
» Mong bạn sẽ có nhưng giây phút bổ ích trên 4rum.
» Cảm ơn sự ủng hộ của bạn.

Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

Latest topics

» Skin 3Bj - Design bởi ßabylove_die - Rip bởi FR [A2Pro]
by thoavip103 Wed Aug 22, 2012 10:05 am

» Xin code khẩn cấp
by wastevip Wed Jan 11, 2012 3:30 pm

» Code banner quảng cáo chạy 2 bên hay đó nha ! :D
by wastevip Wed Jan 11, 2012 2:42 pm

» Cổng Chia Sẻ.Com - Let's share to be Shared
by zhaosin0201 Sat Dec 10, 2011 4:55 pm

» Giảm 40% học phí cho sinh viên khóa tiếng anh giao tiếp với giáo viên bản ngữ
by nhungntbac Thu Sep 22, 2011 3:32 pm

» Tư vấn du lịch nước ngoài
by bycute90 Thu Aug 25, 2011 3:02 pm

» Mảnh giấy tình yêu
by gianggiangonline Thu Apr 21, 2011 10:13 am

» 10 câu nói bất hủ cuả Bill Gates
by votinh_boy Wed Mar 16, 2011 5:16 pm

» Kiểm tra tính hợp lệ của một email
by votinh_boy Sun Mar 13, 2011 6:01 pm

» clip hai` vui :D
by votinh_boy Wed Mar 09, 2011 11:52 pm

» Ghé thăm “đại bản doanh” mới của Facebook
by  Wed Feb 09, 2011 5:48 pm

» Tuyệt chiêu khôi phục dữ liệu trên đĩa bị trầy xước:
by hogiang Wed Feb 09, 2011 5:40 pm

» Ảnh nhoè .........
by votinh_boy Wed Dec 29, 2010 3:18 pm

» Microsoft Office 2010 Blue Edition
by 1959 Sun Oct 03, 2010 8:53 am

» Chàng trai '4 không' trưng biển tìm vợ trên phố
by  Fri Sep 24, 2010 7:05 pm

» Video tạo menu drop
by votinh_boy Wed Sep 15, 2010 6:31 am

Keywords


    Kiểm tra tính hợp lệ của một email

    votinh_boy
    votinh_boy

    Admin
    Admin


    Bài Gửi : 366
    Điểm Số : 6064
    Đến từ : Quỳnh Lưu-Nghệ An
    Ngày Tham Gia : 21/10/2009

    Kiểm tra tính hợp lệ của một email Empty Kiểm tra tính hợp lệ của một email

    Bài gửi by votinh_boy Sun May 02, 2010 7:23 pm

    Bước 1: Dùng mã Javascript để cài đặt hiệu ứng
    Code:
    <script LANGUAGE="Javascript">
    // V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com)
    <!-- Changes:
    /* 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
    International characters) were allowed.

    1.1.3: Added the restriction to only accept addresses ending in two
    Letters (interpreted to be a country code) or one of the known
    TLDs (com, net, org, edu, int, mil, gov, arpa), including the
    New ones (biz, aero, name, coop, info, pro, museum).  One can
    Easily update the list (if ICANN adds even more TLDs in the
    Future) by updating the knownDomsPat variable near the
    Top of the function.  Also, I added a variable at the top
    Of the function that determines whether or not TLDs should be
    Checked at all.  This is good if you are using this function
    Internally (i.e. intranet site) where hostnames don't have to
    Conform to W3C standards and thus internal organization e-mail
    Addresses don't have to either.
    Changed some of the logic so that the function will work properly
    With Netscape 6.

    1.1.2: Fixed a bug where trailing . in e-mail address was passing
    (the bug is actually in the weak regexp engine of the browser; I
    Simplified the regexps to make it work).

    1.1.1: Removed restriction that countries must be preceded by a domain,
    So [You must be registered and logged in to see this link.] is now legal.  However, there's still the
    Restriction that an address must end in a two or three letter
    Word.

    1.1: Rewrote most of the function to conform more closely to RFC 822.

    1.0: Original  */
    // -->

    <!-- Begin
    Function emailCheck (emailStr) {

    /* The following variable tells the rest of the function whether or not
    To verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */

    Var checkTLD=1;

    /* The following is the list of known TLDs that an e-mail address must end with. */

    Var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

    /* The following pattern is used to check if the entered e-mail address
    Fits the user@domain format.  It also is used to separate the username
    From the domain. */

    Var emailPat=/^(.+)@(.+)$/;

    /* The following string represents the pattern for matching all special
    Characters.  We don't want to allow special characters in the address.
    These characters include ( ) < > @ , ; : \ " . [ ] */

    Var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

    /* The following string represents the range of characters allowed in a
    Username or domainname.  It really states which chars aren't allowed.*/

    Var validChars="\[^\\s" + specialChars + "\]";

    /* The following pattern applies if the "user" is a quoted string (in
    Which case, there are no rules about which characters are allowed
    And which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    Is a legal e-mail address. */

    Var quotedUser="(\"[^\"]*\")";

    /* The following pattern applies for domains that are IP addresses,
    Rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    E-mail address. NOTE: The square brackets are required. */

    Var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /* The following string represents an atom (basically a series of non-special characters.) */

    Var atom=validChars + '+';

    /* The following string represents one word in the typical username.
    For example, in [You must be registered and logged in to see this link.], john and doe are words.
    Basically, a word is either an atom or quoted string. */

    Var word="(" + atom + "|" + quotedUser + ")";

    // The following pattern describes the structure of the user

    Var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

    /* The following pattern describes the structure of a normal symbolic
    Domain, as opposed to ipDomainPat, shown above. */

    Var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
    Different pieces that are easy to analyze. */

    Var matchArray=emailStr.match(emailPat);

    If (matchArray==null) {

    /* Too many/few @'s or something; basically, this address doesn't
    Even fit the general mould of a valid e-mail address. */

    Alert("Email address seems incorrect (check @ and .'s)");
    Return false;
    }
    Var user=matchArray[1];
    Var domain=matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    For (i=0; i<user.length; i++) {
    If (user.charCodeAt(i)>127) {
    Alert("Ths username contains invalid characters.");
    Return false;
      }
    }
    For (i=0; i<domain.length; i++) {
    If (domain.charCodeAt(i)>127) {
    Alert("Ths domain name contains invalid characters.");
    Return false;
      }
    }

    // See if "user" is valid

    If (user.match(userPat)==null) {

    // user is not valid

    Alert("The username doesn't seem to be valid.");
    Return false;
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    Host name) make sure the IP address is valid. */

    Var IPArray=domain.match(ipDomainPat);
    If (IPArray!=null) {

    // this is an IP address

    For (var i=1;i<=4;i++) {
    If (IPArray[i]>255) {
    Alert("Destination IP address is invalid!");
    Return false;
      }
    }
    Return true;
    }

    // Domain is symbolic name.  Check if it's valid.
     
    Var atomPat=new RegExp("^" + atom + "$");
    Var domArr=domain.split(".");
    Var len=domArr.length;
    For (i=0;i<len;i++) {
    If (domArr[i].search(atomPat)==-1) {
    Alert("The domain name does not seem to be valid.");
    Return false;
      }
    }

    /* domain name seems valid, but now make sure that it ends in a
    Known top-level domain (like com, edu, gov) or a two-letter word,
    Representing country (uk, nl), and that there's a hostname preceding
    The domain or country. */

    If (checkTLD && domArr[domArr.length-1].length!=2 &&
    DomArr[domArr.length-1].search(knownDomsPat)==-1) {
    Alert("The address must end in a well-known domain or two letter " + "country.");
    Return false;
    }

    // Make sure there's a host name preceding the domain.

    If (len<2) {
    Alert("This address is missing a hostname!");
    Return false;
    }

    // If we've gotten this far, everything's valid!
    Return true;
    }

    //  End -->
    </script>
      <!--
          This script downloaded from [You must be registered and logged in to see this link.]
          Come to view and download over 2000+ free javascript at [You must be registered and logged in to see this link.]
      -->

    Bước 2: Đặt mã HTML bên dưới vào phần BODY
    Code:
    <form name=emailform onSubmit="return emailCheck(this.email.value)">
    Your Email Address:  <input type=text name="email"><br>
    <input type=submit value="Submit">
    </form>
      <!--
          This script downloaded from [You must be registered and logged in to see this link.]
          Come to view and download over 2000+ free javascript at [You must be registered and logged in to see this link.]
      -->

    (nguồn: [You must be registered and logged in to see this link.] )
    votinh_boy
    votinh_boy

    Admin
    Admin


    Bài Gửi : 366
    Điểm Số : 6064
    Đến từ : Quỳnh Lưu-Nghệ An
    Ngày Tham Gia : 21/10/2009

    Kiểm tra tính hợp lệ của một email Empty Re: Kiểm tra tính hợp lệ của một email

    Bài gửi by votinh_boy Sun Mar 13, 2011 6:01 pm

    các bạn chú ý, việc kiểm tra tính hợp lệ này không an toàn cho lắm nếu như người dùng cố tình không cho js thực thi. theo mình được biết thì hiện tại một số quốc gia không cho js chạy trên trình duyệt của mình. thường thì kiểm tra tính hợp lệ của mail coder có thể kiểm tra ngay trên server chứ không kiểm tra trên client.

      Hôm nay: Tue Sep 17, 2024 3:21 am