Validation Rules
These validation rules are available on any EnInput component. They are set by the rules prop, which can either be a string where each rule is separated by a | character or in object format where the rule name is the key and the value is either the rule param or true.
A few basic examples:
The validation messages can be overridden using the custom-messages prop:
alpha_dash
The field under validation may contain alphabetic characters, numbers, dashes, or underscores.
alpha_num
The field under validation may contain alphabetic characters, numbers, dashes, or underscores.
between
The field under validation must have a numeric value bounded by a minimum value and a maximum value.
Params
Example| Name | Type | Description |
|---|---|---|
param | number | Two numeric values split by a comma that the value should be between |
digits
The field under validation must be numeric and have the specified number of digits.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Exact number of digits the value must have. |
excluded
The field under validation must not be one of the provided arguments. An infinte number of comma separated values can be provided.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Comma separated list of values. |
ext
The fields files under validation must match one of the following file extensions
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Comma seprated list of file extensions |
invalid
The field under validation is invalid due to a circumstance outside of normal validation. Dynamically add the invalid rule to mark a field invalid.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Sets the validation message |
is
The field under validation must be an exact match of the passed in parameter.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | The exact value to be validated |
length
The field under validation must exactly have the specified number of items, only works for iterables.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Exact length of the string or length of the array being validated. |
max_value
The field under validation must be a numeric value and must not be greater than the specified value.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | The maximum value to be validated on. |
max
The field under validation length may not exceed the specified length.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Maximum length of the string or length of the array being validated. |
min_value
The field under validation must be a numeric value and must not be less than the specified value.
Params
Example| Name | Type | Description |
|---|---|---|
param | number | The minimum value to be validated on. |
min
The field under validation length may not exceed the specified length.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Minimum length of the string or length of the array being validated. |
min_date
The field under validation may not have a date before specified date.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Minimum date, must be able to be parsed by |
max_date
The field under validation may not have a date after specified date.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Maximum date, must be able to be parsed by |
one_of
The field under validation must have a value that is in the specified list.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Comma separated list of acceptable values. |
not_one_of
The field under validation must have a value that is not in the specified list.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Comma separated list of unacceptable values. |
regex
The field under validation must match the specified regular expression.
Params
Example| Name | Type | Description |
|---|---|---|
param | string | Valid regex string to be validated on. |
double
The field under validation must have a decimal.
Params
Example| Name | Type | Description |
|---|---|---|
param | number | Optional param for exact number of decimal places. |