-
Notifications
You must be signed in to change notification settings - Fork 24
@Length
vivin edited this page Jul 19, 2012
·
3 revisions
@Length
enforces the constraint that the number of characters in the input field must be greater than or equal to one specified-value and lesser than or equal to another specified-value. Meaning, the number of characters in the value of the input element must lie between a certain range of values (both values inclusive).
Syntax for @Length
is:
@Length(min=min-value,
max=max-value , [label=label-text] ,
[message=message-text] ,
[groups=array-of-group-names])
Name | Type | Required | Description |
---|---|---|---|
min |
Integer | yes | A required parameter that specifies the minimum acceptable-number of characters in the value of the field. |
max |
Integer | yes | A required parameter that specifies the maximum acceptable-number of characters in the value of the field. |
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 between {min} and {max} . |
groups |
Array | no | An array of group names that specifies the validation groups that this constraint belongs to. |
<input id = "trackingNumber"
name = "trackingNumber"
type = "text"
data-constraints = '@Length(min=15, max=30)' />
<input id = "trackingNumber"
name = "trackingNumber"
type = "text"
data-constraints = '@Length(min=15, max=30,
label="Tracking Number",
message="{label} can only contain letters and/or numbers!",
groups=[FirstGroup, SecondGroup, ThirdGroup]' />