Diễn đàn Clan Yalz
Bạn đã là thành viên xin hãy đăng nhập, còn chưa thì hãy đăng kí nha!
Diễn đàn Clan Yalz
Bạn đã là thành viên xin hãy đăng nhập, còn chưa thì hãy đăng kí nha!
Diễn đàn Clan Yalz
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.
Diễn đàn Clan Yalz


 
Trang ChínhTrang Chính  Latest imagesLatest images  Đăng kýĐăng ký  Đăng NhậpĐăng Nhập  

Share | 

 

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

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down 
Kiểm tra tính hợp lệ của một email EmptyThu Jun 03, 2010 2:48 am

Yalz÷Kiêu
Thủ lĩnh

Yalz÷Kiêu

Thủ lĩnh

https://clanyalz.forum-viet.com
Số bài gửi Số bài gửi : 244
Ngày tham gia Ngày tham gia : 27/02/2010
Tuổi Tuổi : 30
Đến từ Đến từ : Thiên đường

Bài gửiTiêu đề: Kiểm tra tính hợp lệ của một email

 
Bước 1: Dùng mã Javascript để cài đặt hiệu ứng

Code:
[font=Courier New]<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 [/font][url=http://clanyalz.forum-viet.com/mailto:abc@host.uk][font=Courier New][color=#ff0099]abc@host.uk[/color][/font][/url][font=Courier New] 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 [/font][url=http://clanyalz.forum-viet.com/mailto:john.doe@somewhere.com][font=Courier New][color=#ff0099]john.doe@somewhere.com[/color][/font][/url][font=Courier New], 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 [/font][url=http://www.javascriptbank.com/][font=Courier New][color=#ff0099]www.JavascriptBank.com[/color][/font][/url]
[font=Courier New]      Come to view and download over 2000+ free javascript at [/font][url=http://www.javascriptbank.com/][font=Courier New][color=#ff0099]www.JavascriptBank.com[/color][/font][/url]
[font=Courier New]  -->[/font]

Bước 2: Đặt mã HTML bên dưới vào phần BODY

Code:
[font=Courier New]<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 [/font][url=http://www.javascriptbank.com/][font=Courier New][color=#ff0099]www.JavascriptBank.com[/color][/font][/url]
[font=Courier New]      Come to view and download over 2000+ free javascript at [/font][url=http://www.javascriptbank.com/][font=Courier New][color=#ff0099]www.JavascriptBank.com[/color][/font][/url]
[font=Courier New]  -->[/font]

 

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

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang 
Trang 1 trong tổng số 1 trang

Permissions in this forum:Bạn không có quyền trả lời bài viết
Diễn đàn Clan Yalz :: Phần mềm :: Forum - Css - Code-

Powered by phpBB® Version 2.0. Forumotion..

 
Free forum | ©phpBB | Free forum support | Báo cáo lạm dụng | Thảo luận mới nhất