org.apache.commons.validator

Class GenericTypeValidator

public class GenericTypeValidator extends Object implements Serializable

This class contains basic methods for performing validations that return the correctly typed class based on the validation performed.

Version: $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $

Method Summary
static ByteformatByte(String value)
Checks if the value can safely be converted to a byte primitive.
static ByteformatByte(String value, Locale locale)
Checks if the value can safely be converted to a byte primitive.
static LongformatCreditCard(String value)

Checks if the field is a valid credit card number.

Reference Sean M.

static DateformatDate(String value, Locale locale)

Checks if the field is a valid date.

static DateformatDate(String value, String datePattern, boolean strict)

Checks if the field is a valid date.

static DoubleformatDouble(String value)
Checks if the value can safely be converted to a double primitive.
static DoubleformatDouble(String value, Locale locale)
Checks if the value can safely be converted to a double primitive.
static FloatformatFloat(String value)
Checks if the value can safely be converted to a float primitive.
static FloatformatFloat(String value, Locale locale)
Checks if the value can safely be converted to a float primitive.
static IntegerformatInt(String value)
Checks if the value can safely be converted to a int primitive.
static IntegerformatInt(String value, Locale locale)
Checks if the value can safely be converted to an int primitive.
static LongformatLong(String value)
Checks if the value can safely be converted to a long primitive.
static LongformatLong(String value, Locale locale)
Checks if the value can safely be converted to a long primitive.
static ShortformatShort(String value)
Checks if the value can safely be converted to a short primitive.
static ShortformatShort(String value, Locale locale)
Checks if the value can safely be converted to a short primitive.

Method Detail

formatByte

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

Parameters: value The value validation is being performed on.

Returns: the converted Byte value.

formatByte

public static Byte formatByte(String value, Locale locale)
Checks if the value can safely be converted to a byte primitive.

Parameters: value The value validation is being performed on. locale The locale to use to parse the number (system default if null)

Returns: the converted Byte value.

formatCreditCard

public static Long formatCreditCard(String value)

Checks if the field is a valid credit card number.

Reference Sean M. Burke's script .

Parameters: value The value validation is being performed on.

Returns: the converted Credit Card number.

formatDate

public static Date formatDate(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 to parse the date (system default if null)

Returns: the converted Date value.

formatDate

public static Date formatDate(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.

Returns: the converted Date value.

formatDouble

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

Parameters: value The value validation is being performed on.

Returns: the converted Double value.

formatDouble

public static Double formatDouble(String value, Locale locale)
Checks if the value can safely be converted to a double primitive.

Parameters: value The value validation is being performed on. locale The locale to use to parse the number (system default if null)

Returns: the converted Double value.

formatFloat

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

Parameters: value The value validation is being performed on.

Returns: the converted Float value.

formatFloat

public static Float formatFloat(String value, Locale locale)
Checks if the value can safely be converted to a float primitive.

Parameters: value The value validation is being performed on. locale The locale to use to parse the number (system default if null)

Returns: the converted Float value.

formatInt

public static Integer formatInt(String value)
Checks if the value can safely be converted to a int primitive.

Parameters: value The value validation is being performed on.

Returns: the converted Integer value.

formatInt

public static Integer formatInt(String value, Locale locale)
Checks if the value can safely be converted to an int primitive.

Parameters: value The value validation is being performed on. locale The locale to use to parse the number (system default if null)

Returns: the converted Integer value.

formatLong

public static Long formatLong(String value)
Checks if the value can safely be converted to a long primitive.

Parameters: value The value validation is being performed on.

Returns: the converted Long value.

formatLong

public static Long formatLong(String value, Locale locale)
Checks if the value can safely be converted to a long primitive.

Parameters: value The value validation is being performed on. locale The locale to use to parse the number (system default if null)

Returns: the converted Long value.

formatShort

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

Parameters: value The value validation is being performed on.

Returns: the converted Short value.

formatShort

public static Short formatShort(String value, Locale locale)
Checks if the value can safely be converted to a short primitive.

Parameters: value The value validation is being performed on. locale The locale to use to parse the number (system default if null)vv

Returns: the converted Short value.

Copyright (c) 2001-2004 Apache Software Foundation