org.apache.commons.validator
Class GenericValidator

java.lang.Object
  |
  +--org.apache.commons.validator.GenericValidator
All Implemented Interfaces:
java.io.Serializable

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

This class contains basic methods for performing validations.

Version:
$Revision: 1.13 $ $Date: 2003/03/15 23:18:12 $
Author:
David Winterfeldt, James Turner
See Also:
Serialized Form

Field Summary
static java.lang.String REGEXP_DELIM
          Delimiter to put around a regular expression following Perl 5 syntax.
 
Constructor Summary
GenericValidator()
           
 
Method Summary
protected static java.lang.String getDelimittedRegexp(java.lang.String regexp)
          Adds a '/' on either side of the regular expression.
static boolean isBlankOrNull(java.lang.String value)
          Checks if the field isn't null and length of the field is greater than zero not including whitespace.
static boolean isByte(java.lang.String value)
          Checks if the value can safely be converted to a byte primitive.
static boolean isCreditCard(java.lang.String value)
          Checks if the field is a valid credit card number.
static boolean isDate(java.lang.String value, java.util.Locale locale)
          Checks if the field is a valid date.
static boolean isDate(java.lang.String value, java.lang.String datePattern, boolean strict)
          Checks if the field is a valid date.
static boolean isDouble(java.lang.String value)
          Checks if the value can safely be converted to a double primitive.
static boolean isEmail(java.lang.String value)
          Checks if a field has a valid e-mail address.
static boolean isFloat(java.lang.String value)
          Checks if the value can safely be converted to a float primitive.
static boolean isInRange(double value, double min, double max)
          Checks if a value is within a range (min & max specified in the vars attribute).
static boolean isInRange(float value, float min, float max)
          Checks if a value is within a range (min & max specified in the vars attribute).
static boolean isInRange(int value, int min, int max)
          Checks if a value is within a range (min & max specified in the vars attribute).
static boolean isInRange(short value, short min, short max)
          Checks if a value is within a range (min & max specified in the vars attribute).
static boolean isInt(java.lang.String value)
          Checks if the value can safely be converted to a int primitive.
static boolean isLong(java.lang.String value)
          Checks if the value can safely be converted to a long primitive.
static boolean isShort(java.lang.String value)
          Checks if the value can safely be converted to a short primitive.
static boolean matchRegexp(java.lang.String value, java.lang.String regexp)
          Checks if the value matches the regular expression.
static boolean maxLength(java.lang.String value, int max)
          Checks if the value's length is less than or equal to the max.
static boolean minLength(java.lang.String value, int min)
          Checks if the value's length is greater than or equal to the min.
protected static boolean validateCreditCardLuhnCheck(java.lang.String cardNumber)
          Checks for a valid credit card number.
protected static boolean validateCreditCardPrefixCheck(java.lang.String cardNumber)
          Checks for a valid credit card number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REGEXP_DELIM

public static final java.lang.String REGEXP_DELIM
Delimiter to put around a regular expression following Perl 5 syntax.

See Also:
Constant Field Values
Constructor Detail

GenericValidator

public GenericValidator()
Method Detail

isBlankOrNull

public static boolean isBlankOrNull(java.lang.String value)

Checks if the field isn't null and length of the field is greater than zero not including whitespace.

Parameters:
value - The value validation is being performed on.

matchRegexp

public static boolean matchRegexp(java.lang.String value,
                                  java.lang.String regexp)

Checks if the value matches the regular expression.

Parameters:
value - The value validation is being performed on.
regexp - The regular expression.

isByte

public static boolean isByte(java.lang.String value)

Checks if the value can safely be converted to a byte primitive.

Parameters:
value - The value validation is being performed on.

isShort

public static boolean isShort(java.lang.String value)

Checks if the value can safely be converted to a short primitive.

Parameters:
value - The value validation is being performed on.

isInt

public static boolean isInt(java.lang.String value)

Checks if the value can safely be converted to a int primitive.

Parameters:
value - The value validation is being performed on.

isLong

public static boolean isLong(java.lang.String value)

Checks if the value can safely be converted to a long primitive.

Parameters:
value - The value validation is being performed on.

isFloat

public static boolean isFloat(java.lang.String value)

Checks if the value can safely be converted to a float primitive.

Parameters:
value - The value validation is being performed on.

isDouble

public static boolean isDouble(java.lang.String value)

Checks if the value can safely be converted to a double primitive.

Parameters:
value - The value validation is being performed on.

isDate

public static boolean isDate(java.lang.String value,
                             java.util.Locale locale)

Checks if the field is a valid date. The Locale is used with java.text.DateFormat. The setLenient method is set to false for all.

Parameters:
value - The value validation is being performed on.

isDate

public static boolean isDate(java.lang.String value,
                             java.lang.String datePattern,
                             boolean strict)

Checks if the field is a valid date. The pattern is used with java.text.SimpleDateFormat. If strict is true, then the length will be checked so '2/12/1999' will not pass validation with the format 'MM/dd/yyyy' because the month isn't two digits. The setLenient method is set to false for all.

Parameters:
value - The value validation is being performed on.
datePattern - The pattern passed to SimpleDateFormat.
strict - Whether or not to have an exact match of the datePattern.

isInRange

public static boolean isInRange(int value,
                                int min,
                                int max)

Checks if a value is within a range (min & max specified in the vars attribute).

Parameters:
value - The value validation is being performed on.
min - The minimum value of the range.
max - The maximum value of the range.

isInRange

public static boolean isInRange(float value,
                                float min,
                                float max)

Checks if a value is within a range (min & max specified in the vars attribute).

Parameters:
value - The value validation is being performed on.
min - The minimum value of the range.
max - The maximum value of the range.

isInRange

public static boolean isInRange(short value,
                                short min,
                                short max)

Checks if a value is within a range (min & max specified in the vars attribute).

Parameters:
value - The value validation is being performed on.
min - The minimum value of the range.
max - The maximum value of the range.

isInRange

public static boolean isInRange(double value,
                                double min,
                                double max)

Checks if a value is within a range (min & max specified in the vars attribute).

Parameters:
value - The value validation is being performed on.
min - The minimum value of the range.
max - The maximum value of the range.

isCreditCard

public static boolean isCreditCard(java.lang.String value)

Checks if the field is a valid credit card number.

Translated to Java by Ted Husted (husted@apache.org).
    Reference Sean M. Burke's script at http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl

Parameters:
value - The value validation is being performed on.

validateCreditCardLuhnCheck

protected static boolean validateCreditCardLuhnCheck(java.lang.String cardNumber)

Checks for a valid credit card number.

Translated to Java by Ted Husted (husted@apache.org).
    Reference Sean M. Burke's script at http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl

Parameters:
cardNumber - Credit Card Number

validateCreditCardPrefixCheck

protected static boolean validateCreditCardPrefixCheck(java.lang.String cardNumber)

Checks for a valid credit card number.

Translated to Java by Ted Husted (husted@apache.org).
    Reference Sean M. Burke's script at http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl

Parameters:
cardNumber - Credit Card Number

isEmail

public static boolean isEmail(java.lang.String value)

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

Based on a script by Sandeep V. Tamhankar (stamhankar@hotmail.com), http://javascript.internet.com

Parameters:
value - The value validation is being performed on.

maxLength

public static boolean maxLength(java.lang.String value,
                                int max)

Checks if the value's length is less than or equal to the max.

Parameters:
value - The value validation is being performed on.
max - The maximum length.

minLength

public static boolean minLength(java.lang.String value,
                                int min)

Checks if the value's length is greater than or equal to the min.

Parameters:
value - The value validation is being performed on.
min - The minimum length.

getDelimittedRegexp

protected static java.lang.String getDelimittedRegexp(java.lang.String regexp)
Adds a '/' on either side of the regular expression.



Copyright (c) 2001-2002 - Apache Software Foundation