@IsNumeric annotation

back to index

Action

Requires that the value be a numeric value. If it is not, it will attempt to perform a conversion according either using a provided pattern, or using the locale-dependant default pattern. Usually numeric conversions are performed automatically. You should use this annotation only if you want to specify a custom numeric pattern.

Javadoc Ref :  Javadoc reference@IsNumeric

 Input Types 1
Object
 Output Types
Number
   

1Automatic conversion will take place if the provided input does not match any of the input classes, as described in the conversions part of the manual.

Arguments

value

Pattern to use when parsing the data, if it is not natively numeric

defaultValue

If set to something different than the default (the empty string), specifies a default value that is used whenever a null value is received. The default value is parsed to a BigDecimal. Unlike @IsDate and similar annotations, the default value does NOT go through the pattern parser, in order to avoid dependancies with different locales (Since, unlike dates, some fundamental symbols in the pattern are not literal - like decimal and thousands separators)

message

Literal message to use if validation fails.

errorCode
Error code to use if validation fails.
messageKey
Message key to use if validation fails.

 

Example

@IsNumeric(value="0,000.000",defaultValue="1234.981")
private double doubleFieldWithDefault;

@IsNumeric
private BigDecimal bdField;

@IsNumeric(value="0,000.000",defaultValue="1234.981")
private String string;