org.apache.commons.validator

Class GenericValidator

Implemented Interfaces:
Serializable

public class GenericValidator
extends java.lang.Object
implements Serializable

This class contains basic methods for performing validations.

Nested Class Summary

Field Summary

static String
REGEXP_DELIM
Deprecated. Use ValidatorUtils.REGEXP_DELIMITER instead.
private static CreditCardValidator
creditCardValidator
CreditCardValidator used in wrapper method.
private static UrlValidator
urlValidator
UrlValidator used in wrapper method.

Method Summary

protected static String
getDelimittedRegexp(String regexp)
Deprecated. use ValidatorUtils.getDelimitedRegExp() instead.
static boolean
isBlankOrNull(String value)
Checks if the field isn't null and length of the field is greater than zero not including whitespace.
static boolean
isByte(String value)
Checks if the value can safely be converted to a byte primitive.
static boolean
isCreditCard(String value)
Checks if the field is a valid credit card number.
static boolean
isDate(String value, Locale locale)
Checks if the field is a valid date.
static boolean
isDate(String value, String datePattern, boolean strict)
Checks if the field is a valid date.
static boolean
isDouble(String value)
Checks if the value can safely be converted to a double primitive.
static boolean
isEmail(String value)
Checks if a field has a valid e-mail address.
static boolean
isFloat(String value)
Checks if the value can safely be converted to a float primitive.
static boolean
isInRange(byte value, byte min, byte max)
Checks if a value is within a range (min & max specified in the vars attribute).
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(long value, long min, long 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(String value)
Checks if the value can safely be converted to a int primitive.
static boolean
isLong(String value)
Checks if the value can safely be converted to a long primitive.
static boolean
isShort(String value)
Checks if the value can safely be converted to a short primitive.
static boolean
isUrl(String value)
Checks if a field is a valid url address.
static boolean
matchRegexp(String value, String regexp)
Checks if the value matches the regular expression.
static boolean
maxLength(String value, int max)
Checks if the value's length is less than or equal to the max.
static boolean
minLength(String value, int min)
Checks if the value's length is greater than or equal to the min.
protected static boolean
validateCreditCardLuhnCheck(String cardNumber)
Deprecated. This functionality has moved to CreditCardValidator.
protected boolean
validateCreditCardPrefixCheck(String cardNumber)
Deprecated. This functionality has move to CreditCardValidator.

Field Details

REGEXP_DELIM

public static final String REGEXP_DELIM

Deprecated. Use ValidatorUtils.REGEXP_DELIMITER instead.

Delimiter to put around a regular expression following Perl 5 syntax.


creditCardValidator

private static final CreditCardValidator creditCardValidator
CreditCardValidator used in wrapper method.


urlValidator

private static final UrlValidator urlValidator
UrlValidator used in wrapper method.

Method Details

getDelimittedRegexp

protected static String getDelimittedRegexp(String regexp)

Deprecated. use ValidatorUtils.getDelimitedRegExp() instead.

Adds a '/' on either side of the regular expression.


isBlankOrNull

public static boolean isBlankOrNull(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.


isByte

public static boolean isByte(String value)
Checks if the value can safely be converted to a byte primitive.

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


isCreditCard

public static boolean isCreditCard(String value)
Checks if the field is a valid credit card number.

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


isDate

public static boolean isDate(String value,
                             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.
locale - The locale to use for the date format, defaults to the default system default if null.


isDate

public static boolean isDate(String value,
                             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.


isDouble

public static boolean isDouble(String value)
Checks if the value can safely be converted to a double primitive.

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


isEmail

public static boolean isEmail(String value)
Checks if a field has a valid e-mail address.

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


isFloat

public static boolean isFloat(String value)
Checks if the value can safely be converted to a float primitive.

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


isInRange

public static boolean isInRange(byte value,
                                byte min,
                                byte 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.


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(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(long value,
                                long min,
                                long 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.


isInt

public static boolean isInt(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(String value)
Checks if the value can safely be converted to a long primitive.

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


isShort

public static boolean isShort(String value)
Checks if the value can safely be converted to a short primitive.

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


isUrl

public static boolean isUrl(String value)
Checks if a field is a valid url address. If you need to modify what is considered valid then consider using the UrlValidator directly.

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


matchRegexp

public static boolean matchRegexp(String value,
                                  String regexp)
Checks if the value matches the regular expression.

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


maxLength

public static boolean maxLength(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(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.


validateCreditCardLuhnCheck

protected static boolean validateCreditCardLuhnCheck(String cardNumber)

Deprecated. This functionality has moved to CreditCardValidator.

Checks for a valid credit card number.

Parameters:
cardNumber - Credit Card Number.


validateCreditCardPrefixCheck

protected boolean validateCreditCardPrefixCheck(String cardNumber)

Deprecated. This functionality has move to CreditCardValidator.

Checks for a valid credit card number.

Parameters:
cardNumber - Credit Card Number.


Copyright (c) 2001-2004 Apache Software Foundation