org.apache.commons.validator
Class EmailValidator
java.lang.Object
org.apache.commons.validator.EmailValidator
public class EmailValidator
extends java.lang.Object
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"
.
$Revision: 478560 $ $Date: 2006-11-23 13:09:27 +0000 (Thu, 23 Nov 2006) $
static EmailValidator | getInstance() - Returns the Singleton instance of this validator.
|
boolean | isValid(String email) - Checks if a field has a valid e-mail address.
|
protected boolean | isValidDomain(String domain) - Returns true if the domain component of an email address is valid.
|
protected boolean | isValidIpAddress(Perl5Util ipAddressMatcher) - Validates an IP address.
|
protected boolean | isValidSymbolicDomain(String domain) - Validates a symbolic domain name.
|
protected boolean | isValidUser(String user) - Returns true if the user component of an email address is valid.
|
protected String | stripComments(String emailStr) - Recursively remove comments, and replace with a single space.
|
ATOM
private static final String ATOM
ATOM_PATTERN
private static final String ATOM_PATTERN
DOMAIN_PATTERN
private static final String DOMAIN_PATTERN
EMAIL_PATTERN
private static final String EMAIL_PATTERN
EMAIL_VALIDATOR
private static final EmailValidator EMAIL_VALIDATOR
Singleton instance of this class.
IP_DOMAIN_PATTERN
private static final String IP_DOMAIN_PATTERN
LEGAL_ASCII_PATTERN
private static final String LEGAL_ASCII_PATTERN
QUOTED_USER
private static final String QUOTED_USER
SPECIAL_CHARS
private static final String SPECIAL_CHARS
TLD_PATTERN
private static final String TLD_PATTERN
USER_PATTERN
private static final String USER_PATTERN
VALID_CHARS
private static final String VALID_CHARS
WORD
private static final String WORD
EmailValidator
protected EmailValidator()
Protected constructor for subclasses to use.
getInstance
public static EmailValidator getInstance()
Returns the Singleton instance of this validator.
- singleton instance of this validator.
isValid
public boolean isValid(String email)
Checks if a field has a valid e-mail address.
email
- The value validation is being performed on. A null
value is considered invalid.
- true if the email address is valid.
isValidDomain
protected boolean isValidDomain(String domain)
Returns true if the domain component of an email address is valid.
domain
- being validatied.
- true if the email address's domain is valid.
isValidIpAddress
protected boolean isValidIpAddress(Perl5Util ipAddressMatcher)
Validates an IP address. Returns true if valid.
ipAddressMatcher
- Pattren matcher
- true if the ip address is valid.
isValidSymbolicDomain
protected boolean isValidSymbolicDomain(String domain)
Validates a symbolic domain name. Returns true if it's valid.
domain
- symbolic domain name
- true if the symbolic domain name is valid.
isValidUser
protected boolean isValidUser(String user)
Returns true if the user component of an email address is valid.
- true if the user name is valid.
stripComments
protected String stripComments(String emailStr)
Recursively remove comments, and replace with a single space. The simpler
regexps in the Email Addressing FAQ are imperfect - they will miss escaped
chars in atoms, for example.
Derived From Mail::RFC822::Address
emailStr
- The email address
- address with comments removed.
Copyright (c) 2001-2004 Apache Software Foundation