Available Constraints
Below are all the currently supported constraints. If you need more you can create your own Custom validators.
Reference
Constraint | Type | Default | |
| boolean | false | Whether the property must have a non-null value |
| string | string | Validates that the value is of a certain format type. Our included types are: ssn,email,url,alpha,boolean,date,usdate,eurodate,numeric,GUID,UUID,integer,string,telephone,zipcode,ipaddress,creditcard,binary,component,query,struct,json,xml |
| numeric or range | --- | The size or length of the value which can be a struct, string, array, or query. The value can be a single numeric value or our cool ranges. Ex: size=4, size=6..8, size=-5..0 |
| range | --- | Range is a range of values the property value should exist in. Ex: range=1..10, range=6..8 |
| regular expression | --- | The regular expression to try and match the value with for validation. This is a no case regex check. |
| propertyName | --- | Makes sure the value of the constraint is the same as the value of another property in the object. This is a case sensitive check. |
| propertyName | --- | Makes sure the value of the constraint is the same as the value of another property in the object with no case sensitivity. |
| string list | --- | A list of values that the property value must exist in |
| string | --- | Do discrete math in the property value. The valid values are: eq,neq,lt,lte,gt,gte. Example: discrete="eq:4" or discrete="lte:10" |
| UDF or closure | --- | I can do my own custom validation by doing an inline closure (CF 10 or Railo only) or a pointer to a custom defined function. The function must return boolean and accepts two parameters: value and target. |
| method name | --- | The name of a method to call in the target object for validation. The function must return boolean and accepts two parameters: value and target. |
| numeric | --- | The value must be greater than or equal to this minimum value |
| numeric | --- | The value must be less than or equal to this maximum value |
| instantiation path or wirebox DSL | --- | You can also build your own validators instead of our internal ones. This value will be the instantiation path to the validator or a wirebox id string. Example: validator="mymodel.validators.MyValidator", validator="id:MyValidator" |
Custom Validator
With the validator
constraint you can specify your own custom validator, but if you need your own parameters for your validator this is a bit limited. You can also specify YourOwnValidator
as constraint label where YourOwnValidator
is a wirebox id string. In this case you can specify your own parameters.
See Advanced Custom Validators for details.
WARNING: You can't do a normal wirebox mapping for YourOwnValidator
in your main application. A validator needs an IValidator
interface from the cbvalidation
module. When wirebox inspects the binder, the cbvalidation
module is not loaded yet, so it will error. This can be solved by defining your custom validators in an own module (depending on cbvalidation
) or by mapping your validator in the afterConfigurationLoad()
method of your binder, e.g in config/wirebox.cfc
Last updated