Here are a couple of useful things, but in general there is no way to
fully validate an email address without sending an email and seeing
if it bounces.
JavaScript to do initial (simple) validation of the address:
function validateEmail(email) {
if (email == null || email.length == 0) {
return null;
}
var syntaxMsg =
"Your E-mail address should look like myName@domain.\n\n" +
"Example: \"[EMAIL PROTECTED]\"\n\n";
var msgPrefix = syntaxMsg + '"' + email + '" ';
var atIndex = email.indexOf("@");
if (atIndex == -1) {
return msgPrefix + "does not have an @ sign";
}
var name = email.substring(0, atIndex);
if (name.length == 0) {
return msgPrefix + "does not have a name before " +
"the @ sign";
}
var domain = email.substring(atIndex + 1, email.length);
if (domain.length == 0) {
return msgPrefix + " does not have domain name after the @
sign";
}
var lastDotIndex = email.lastIndexOf(".");
if (lastDotIndex == -1 || lastDotIndex == email.length - 1) {
return msgPrefix + " has no top-level domain, " +
"such as .com or .au";
}
var topDomain = email.substring(lastDotIndex + 1).toLowerCase();
if (topDomain.length < 2) {
return syntaxMsg + '"' + topDomain + "\" is too short to be
" +
"a top level domain, such as .com or .au";
}
var tld = new Array("com", "edu", "gov", "net", "org", "mil",
"int", "arpa", "nato", "firm", "shop",
"web",
"arts", "rec", "info", "nom");
var found = false;
for (i = 0; i < tld.length; ++i) {
if (topDomain == tld[i]) {
found = true;
break;
}
}
if (!found && topDomain.length > 2) {
return syntaxMsg + '"' + topDomain + "\" is not one of " +
"the available top-level domain names, and it is too " +
"long to be a country code";
}
return null;
}
This code includes the proposed new to-level domains, just in case they
get
approved.
On the servlet side, take a look at
http://web.theorem.com/java/index.htm#MXLOOKUPClass
This class allows you do trivially look up DNS MX records for a domain.
This
means you can verify that the domain is somewhat reasonable, though it's
not
foolproof -- for instance, there are real registered domains for yhaoo,
yhao,
and yaho, owned by random cybersquatters.
The complete list of valid top-level domains can be found at
http://www.siteware.ch/webresources/domains/
among other places.
HTH,
Rod McChesney, Korobra
Vallikun Kathiresan wrote:
>
> I am using the SMTPClient to send email to myself when some one fills out a form. I
>would like to know how I can ensure their email address is correct becuase I do not
>send email back to them for a couple of days until their request is processed. ANY
>HELP IS GREATLY APPRECIATED
>
> Thanks
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html