Skip to content
Luis Majano edited this page Feb 5, 2016 · 2 revisions

Below are all the currently supported constraints:

propertyName = {
	// required field or not, includes null values
	required : boolean [false],
	
	// specific type constraint, one in the list.
	type  : (ssn,email,url,alpha,boolean,date,usdate,eurodate,numeric,GUID,UUID,integer,string,telephone,zipcode,ipaddress,creditcard,binary,component,query,struct,json,xml),

	// size or length of the value which can be a (struct,string,array,query)
	size  : numeric or range, eg: 10 or 6..8
	
	// range is a range of values the property value should exist in
	range : eg: 1..10 or 5..-5
	
	// regex validation
	regex : valid no case regex
	
	// same as another property
	sameAs : propertyName
	
	// same as but with no case
	sameAsNoCase : propertyName
	
	// value in list
	inList : list

	// value is unique in the database via the cborm module, it must be installed
	unique : true
	
	// discrete math modifiers
	discrete : (gt,gte,lt,lte,eq,neq):value
	
	// UDF to use for validation, must return boolean accept the incoming value and target object, validate(value,target):boolean
	udf = variables.UDF or this.UDF or a closure.
	
	// Validation method to use in the target object must return boolean accept the incoming value and target object 
	method : methodName
	
	// Custom validator, must implement coldbox.system.validation.validators.IValidator
	validator : path or wirebox id, example: 'mypath.MyValidator' or 'id:MyValidator'
	
	// min value
	min : value
	
	// max value
	max : value
}

Here is a little reference table for you:

Constraint Type Default Description
required boolean false Whether the property must have a non-null value
type 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
size 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 --- Range is a range of values the property value should exist in. Ex: range=1..10, range=6..8
regex regular expression --- The regular expression to try and match the value with for validation. This is a no case regex check.
sameAs 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.
sameAsNoCase propertyName --- Makes sure the value of the constraint is the same as the value of another property in the object with no case sensitivity.
inList string list --- A list of values that the property value must exist in
discrete 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 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 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.
min numeric --- The value must be greater than or equal to this minimum value
max numeric --- The value must be less than or equal to this maximum value
validator 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"

Child Chapters