Skip to content

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

The field under validation may only contain alphabetic characters.

Example

alpha_dash

The field under validation may contain alphabetic characters, numbers, dashes, or underscores.

Example

alpha_num

The field under validation may contain alphabetic characters, numbers, dashes, or underscores.

Example

alpha_spaces

The field under validation may contain alphabetic characters or spaces.

Example

between

The field under validation must have a numeric value bounded by a minimum value and a maximum value.

Params
NameTypeDescription
paramnumber

Two numeric values split by a comma that the value should be between

Example

digits

The field under validation must be numeric and have the specified number of digits.

Params
NameTypeDescription
paramstring

Exact number of digits the value must have.

Example

email

The field under validation must be a valid email.

Example

excluded

The field under validation must not be one of the provided arguments. An infinte number of comma separated values can be provided.

Params
NameTypeDescription
paramstring

Comma separated list of values.

Example

ext

The fields files under validation must match one of the following file extensions

Params
NameTypeDescription
paramstring

Comma seprated list of file extensions

Example

image

The file under validation must be an image.

Example

integer

The field under validation must be a valid integer value.

Example

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
NameTypeDescription
paramstring

Sets the validation message

Example

is

The field under validation must be an exact match of the passed in parameter.

Params
NameTypeDescription
paramstring

The exact value to be validated

Example

length

The field under validation must exactly have the specified number of items, only works for iterables.

Params
NameTypeDescription
paramstring

Exact length of the string or length of the array being validated.

Example

max_value

The field under validation must be a numeric value and must not be greater than the specified value.

Params
NameTypeDescription
paramstring

The maximum value to be validated on.

Example

max

The field under validation length may not exceed the specified length.

Params
NameTypeDescription
paramstring

Maximum length of the string or length of the array being validated.

Example

min_value

The field under validation must be a numeric value and must not be less than the specified value.

Params
NameTypeDescription
paramnumber

The minimum value to be validated on.

Example

min

The field under validation length may not exceed the specified length.

Params
NameTypeDescription
paramstring

Minimum length of the string or length of the array being validated.

Example

min_date

The field under validation may not have a date before specified date.

Params
NameTypeDescription
paramstring

Minimum date, must be able to be parsed by new Date()

Example

max_date

The field under validation may not have a date after specified date.

Params
NameTypeDescription
paramstring

Maximum date, must be able to be parsed by new Date()

Example

one_of

The field under validation must have a value that is in the specified list.

Params
NameTypeDescription
paramstring

Comma separated list of acceptable values.

Example

not_one_of

The field under validation must have a value that is not in the specified list.

Params
NameTypeDescription
paramstring

Comma separated list of unacceptable values.

Example

regex

The field under validation must match the specified regular expression.

Params
NameTypeDescription
paramstring

Valid regex string to be validated on.

Example

double

The field under validation must have a decimal.

Params
NameTypeDescription
paramnumber

Optional param for exact number of decimal places.

Example

Example