org.apache.commons.validator.routines
Class EmailValidator

java.lang.Object
  extended by org.apache.commons.validator.routines.EmailValidator
All Implemented Interfaces:
java.io.Serializable

public class EmailValidator
extends java.lang.Object
implements java.io.Serializable

Perform email validations.

This class is a Singleton; you can retrieve the instance via the getInstance() method.

Based on a script by Sandeep V. Tamhankar http://javascript.internet.com

This implementation is not guaranteed to catch all possible errors in an email address. For example, an address like nobody@noplace.somedog will pass validator, even though there is no TLD "somedog"

.

Since:
Validator 1.4
Version:
$Revision: 594904 $ $Date: 2007-11-14 15:30:27 +0100 (Mi, 14. Nov 2007) $
See Also:
Serialized Form

Field Summary
private static java.util.regex.Pattern EMAIL_PATTERN
           
private static java.lang.String EMAIL_REGEX
           
private static EmailValidator EMAIL_VALIDATOR
          Singleton instance of this class.
private static java.util.regex.Pattern IP_DOMAIN_PATTERN
           
private static java.lang.String IP_DOMAIN_REGEX
           
private static java.lang.String LEGAL_ASCII_REGEX
           
private static java.util.regex.Pattern MATCH_ASCII_PATTERN
           
private static java.lang.String QUOTED_USER
           
private static java.lang.String SPECIAL_CHARS
           
private static java.util.regex.Pattern USER_PATTERN
           
private static java.lang.String USER_REGEX
           
private static java.lang.String VALID_CHARS
           
private static java.lang.String WORD
           
 
Constructor Summary
protected EmailValidator()
          Protected constructor for subclasses to use.
 
Method Summary
static EmailValidator getInstance()
          Returns the Singleton instance of this validator.
 boolean isValid(java.lang.String email)
          Checks if a field has a valid e-mail address.
protected  boolean isValidDomain(java.lang.String domain)
          Returns true if the domain component of an email address is valid.
protected  boolean isValidUser(java.lang.String user)
          Returns true if the user component of an email address is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPECIAL_CHARS

private static final java.lang.String SPECIAL_CHARS
See Also:
Constant Field Values

VALID_CHARS

private static final java.lang.String VALID_CHARS
See Also:
Constant Field Values

QUOTED_USER

private static final java.lang.String QUOTED_USER
See Also:
Constant Field Values

WORD

private static final java.lang.String WORD
See Also:
Constant Field Values

LEGAL_ASCII_REGEX

private static final java.lang.String LEGAL_ASCII_REGEX
See Also:
Constant Field Values

EMAIL_REGEX

private static final java.lang.String EMAIL_REGEX
See Also:
Constant Field Values

IP_DOMAIN_REGEX

private static final java.lang.String IP_DOMAIN_REGEX
See Also:
Constant Field Values

USER_REGEX

private static final java.lang.String USER_REGEX
See Also:
Constant Field Values

MATCH_ASCII_PATTERN

private static final java.util.regex.Pattern MATCH_ASCII_PATTERN

EMAIL_PATTERN

private static final java.util.regex.Pattern EMAIL_PATTERN

IP_DOMAIN_PATTERN

private static final java.util.regex.Pattern IP_DOMAIN_PATTERN

USER_PATTERN

private static final java.util.regex.Pattern USER_PATTERN

EMAIL_VALIDATOR

private static final EmailValidator EMAIL_VALIDATOR
Singleton instance of this class.

Constructor Detail

EmailValidator

protected EmailValidator()
Protected constructor for subclasses to use.

Method Detail

getInstance

public static EmailValidator getInstance()
Returns the Singleton instance of this validator.

Returns:
singleton instance of this validator.

isValid

public boolean isValid(java.lang.String email)

Checks if a field has a valid e-mail address.

Parameters:
email - The value validation is being performed on. A null value is considered invalid.
Returns:
true if the email address is valid.

isValidDomain

protected boolean isValidDomain(java.lang.String domain)
Returns true if the domain component of an email address is valid.

Parameters:
domain - being validated.
Returns:
true if the email address's domain is valid.

isValidUser

protected boolean isValidUser(java.lang.String user)
Returns true if the user component of an email address is valid.

Parameters:
user - being validated
Returns:
true if the user name is valid.


Copyright (c) 2001-2004 Apache Software Foundation