Package org.apache.commons.validator
Class GenericTypeValidator
java.lang.Object
org.apache.commons.validator.GenericTypeValidator
- All Implemented Interfaces:
Serializable
This class contains basic methods for performing validations that return the
correctly typed class based on the validation performed.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Will be private in the next major version. -
Method Summary
Modifier and TypeMethodDescriptionstatic Byte
formatByte
(String value) Checks if the value can safely be converted to a byte primitive.static Byte
formatByte
(String value, Locale locale) Checks if the value can safely be converted to a byte primitive.static Long
formatCreditCard
(String value) Checks if the field is a valid credit card number.static Date
formatDate
(String value, String datePattern, boolean strict) Checks if the field is a valid date.static Date
formatDate
(String value, Locale locale) Checks if the field is a valid date.static Double
formatDouble
(String value) Checks if the value can safely be converted to a double primitive.static Double
formatDouble
(String value, Locale locale) Checks if the value can safely be converted to a double primitive.static Float
formatFloat
(String value) Checks if the value can safely be converted to a float primitive.static Float
formatFloat
(String value, Locale locale) Checks if the value can safely be converted to a float primitive.static Integer
Checks if the value can safely be converted to an int primitive.static Integer
Checks if the value can safely be converted to an int primitive.static Long
formatLong
(String value) Checks if the value can safely be converted to a long primitive.static Long
formatLong
(String value, Locale locale) Checks if the value can safely be converted to a long primitive.static Short
formatShort
(String value) Checks if the value can safely be converted to a short primitive.static Short
formatShort
(String value, Locale locale) Checks if the value can safely be converted to a short primitive.
-
Constructor Details
-
GenericTypeValidator
Deprecated.Will be private in the next major version.Constructs a new instance.
-
-
Method Details
-
formatByte
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
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
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
Checks if the field is a valid date.The
Locale
is used withDateFormat
. TheDateFormat.setLenient(boolean)
method is set tofalse
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
Checks if the field is a valid date.The pattern is used with
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. TheDateFormat.setLenient(boolean)
method is set tofalse
for all.- Parameters:
value
- The value validation is being performed on.datePattern
- The pattern passed toSimpleDateFormat
.strict
- Whether or not to have an exact match of the datePattern.- Returns:
- the converted Date value.
-
formatDouble
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
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
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
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
Checks if the value can safely be converted to an int primitive.- Parameters:
value
- The value validation is being performed on.- Returns:
- the converted Integer value.
-
formatInt
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
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
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
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
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)- Returns:
- the converted Short value.
-