org.randomcoder.validation
Class DataValidationUtils

java.lang.Object
  extended by org.randomcoder.validation.DataValidationUtils

public final class DataValidationUtils
extends Object

Convenience methods to validate common data types.

 Copyright (c) 2006, Craig Condit. All rights reserved.
         
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
         
 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
             
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 


Method Summary
static String canonicalizeDomainName(String domain)
          Returns the canonical representation of a domain name.
static String canonicalizeTagName(String name)
          Derives a canonical representation of a tag name.
static boolean isValidDomainName(String domain)
          Determines whether a domain name is valid or not.
static boolean isValidDomainWildcard(String domain)
          Determines if the given string matches a domain name wildcard.
static boolean isValidEmailAddress(String email)
          Validates email addresses according to RFC2822.
static boolean isValidEmailAddress(String email, boolean strict, boolean local, boolean wildcard)
          Validates email addresses according to RFC2822.
static boolean isValidIpAddress(String ipAddress)
          Determines if a specified IP address is valid.
static boolean isValidLocalEmailAccount(String email)
          Validates local email account names.
static boolean isValidUrl(String url)
          Determines if a specified URL is valid.
static boolean isValidUrl(String url, String... allowedProtocols)
          Determines if a specified URL is valid.
static String[] splitEmailAddress(String email)
          Splits an email address into its local and domain parts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

canonicalizeDomainName

public static String canonicalizeDomainName(String domain)
Returns the canonical representation of a domain name.

Parameters:
domain - domain nam
Returns:
domain name with

isValidDomainName

public static boolean isValidDomainName(String domain)
Determines whether a domain name is valid or not.

NOTE: This method does not handle internationalized domain names.

Parameters:
domain - domain name
Returns:
true if valid, false otherwise

isValidDomainWildcard

public static boolean isValidDomainWildcard(String domain)
Determines if the given string matches a domain name wildcard.

Parameters:
domain - domain name
Returns:
true if valid, false otherwise

isValidLocalEmailAccount

public static boolean isValidLocalEmailAccount(String email)
Validates local email account names.

Parameters:
email - email account
Returns:
true if valid email address, false otherwise

isValidIpAddress

public static boolean isValidIpAddress(String ipAddress)
Determines if a specified IP address is valid.

NOTE: This is IPv4 only.

Parameters:
ipAddress - ip address to test
Returns:
true if valid, false otherwise

isValidUrl

public static boolean isValidUrl(String url)
Determines if a specified URL is valid.

This validates a URL, and restricts the protocols to http and https.

Parameters:
url - URL to validate
Returns:
true if valid, false otherwise

isValidUrl

public static boolean isValidUrl(String url,
                                 String... allowedProtocols)
Determines if a specified URL is valid.

Parameters:
url - URL to validate
allowedProtocols - array of valid protocols
Returns:
true if valid, false otherwise

splitEmailAddress

public static String[] splitEmailAddress(String email)
Splits an email address into its local and domain parts.

Parameters:
email - email address
Returns:
String[] { local, domain }

isValidEmailAddress

public static boolean isValidEmailAddress(String email)
Validates email addresses according to RFC2822.

This is equivalent to calling isValidEmailAddress(String, boolean, boolean, boolean) with strict, local, and wildcard set to false.

Parameters:
email - email address
Returns:
true if valid email address, false otherwise.

isValidEmailAddress

public static boolean isValidEmailAddress(String email,
                                          boolean strict,
                                          boolean local,
                                          boolean wildcard)
Validates email addresses according to RFC2822.

Parameters:
email - email address
strict - if name must be usable in DNS zone file
local - if local addresses are to be allowed
wildcard - if wildcards are to be allowed
Returns:
true if valid email address, false otherwise

canonicalizeTagName

public static String canonicalizeTagName(String name)
Derives a canonical representation of a tag name.

Parameters:
name - tag name
Returns:
canonical tag name


Copyright © 2006-2010 Craig Condit. All Rights Reserved.