By default if a constraint fails an error message will be set in the result objects for you in English. If you would like to have your own custom messages for specific constraints you can do so by following the constraint message convention:
Just add the name of the constraint you like and append to it the word Message and you are ready to roll:
Below are all the currently supported constraints. If you need more you can create your own Custom validators as well.
The field must be yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance.
The field must be alphabetical ONLY
The field must pass certain discrete math operations using the format: operator:value
gt
- Greater than the value
gte
- Greater than or equal to the value
lt
- Less than the value
lte
- Less than or equal to the value
eq
- Equal to the value
neq
- Not equal to the value
The field must be in the included list
The field must be less than or equal to the defined value
The methodName
will be called on the target object and it will pass in validationData and targetValue. It must return a boolean response: true = pass, false = fail.
The field must be greater than or equal to the defined value
The field must be within the range values and the validation data must follow the range pattern: min..max
The field must pass the regular expression match with no case sensitivity
The field must have some type of value and not null.
the field under validation must be present and not empty if the anotherfield
field is equal to the passed value
.
The field under validation must be present and not empty unless the anotherfield
field is equal to the passed
The field must be the same as another field with no case sensitivity
The field must be the same as another field with case sensitivity
The field value size must be within the range values and the validation data must follow the range pattern: min..max.
Value can be a (struct,string,array,query)
One of the most versatile validators. It can test if the value is of the following specific types:
alpha
array
binary
boolean
component
creditcard
date
eurodate
float
GUID
integer
ipaddress
json
numeric
query
ssn
string
struct
telephone
url
usdate
UUID
xml
zipcode
The field value will be passed to the declared closure/lambda to use for validation, must return boolean accept the incoming value and target object, validate(value,target):boolean
The field must be a unique value in a specific database table. The validation data is a struct with the following keys:
table
: The name of the table to check
column
: The column to check, defaults to the property field in check
The field value will be passed to the validator CFC to be used for validation. Please see Custom Validators
We also setup lots of global {Key}
replacements for your messages and also several that the core constraint validators offer as well. This is great for adding these customizations on your custom messages and also your i18n messages (Keep Reading):
{rejectedValue}
- The rejected value
{field or property}
- The property or field that was validated
{validationType}
- The name of the constraint validator
{validationData}
- The value of the constraint definition, e.g size=5..10, then this value is 5..10
{DiscreteValidator}
- operation, operationValue
{InListValidator}
- inList
{MaxValidator}
- max
{MinValidator}
- min
{RangeValidator}
- range, min, max
{RegexValidator}
- regex
{SameAsValidator}
, {SameAsNoCaseValidator}
- sameas
{SizeValidator}
- size, min, max
{TypeValidator}
- type