Skip to content
troyji edited this page Aug 16, 2011 · 2 revisions

This @IsNumeric annotation is scheduled for deprecation. In versions later than 1.2.2 this annotation has been replaced by the @Numeric annotation. In addition, the behavior of @Numeric has changed to support only non-negative numbers. A new constraint, @Integer, mimics the old behavior of @IsNumeric.

Overview

@Numeric enforces the constraint that the value of an input field can only contain numbers.

Syntax

Syntax for @Numeric is:

@Numeric([label=label-text] , [message=message-text] , [groups=array-of-group-names])

Parameters

Name Type Required Description
label String no An optional parameter that specifies the label for this input element. Labels are a way to provide friendly names to input elements. If the constraint fails to validate, the value in this field will be used in the default error message. If the constraint has a custom error message which contains {labe}, the value of this parameter will be substituted in the place of {label}.
message String no An optional parameter that specifies the error message to use when this constraint fails. The value for this field can contain interpolations of parameters used by the constraint . For example: {label} needs to be {param1}.
groups Array no An array of group names that specifies the validation groups that this constraint belongs to.

Examples

Basic usage:

<input id = "score"
       name = "score"
       type = "text"
       data-constraints = '@Numeric' />

Usage with optional parameters:

<input id = "score"
       name = "score"
       type = "text"
       data-constraints = '@Numeric(label="Score", 
                                      message="{label} needs to be a number!"
                                      groups=[FirstGroup, SecondGroup, ThirdGroup]' />
Clone this wiki locally