Blog

Luis Majano

February 26, 2012

Spread the word


Share your thoughts

Just a quick announcement that we now have finally implemented a validation engine and aggregator in ColdBox for 3.5 release.  And in true professional open source style, fully documented: http://wiki.coldbox.org/wiki/Validation.cfm.  It has an embedded validation engine but it also allows you to use ANY validation framework within ANY ColdBox application as long as it satisfies a few interfaces.  Check out our documentation page but here is a little teaser:

 

ColdBox sports its own server side validation engine so it can provide you with a unified approach to object validation. We have based it on several interfaces, so you can also use any validation framework in your ColdBox applications as long as they implement the required interfaces. Hyrule by Dan Vega is the easiest to port as it was the framework that inspired us. ColdBox validation is based on a way to declaratively specify validation rules for properties or fields in an object. The constraints can exist inside of the target object or you can define constraints in your ColdBox configuration file so you can reuse validation constraints or as we call them: shared constraints.

component persistent="true"{
	 
	...

	// Validation
	this.constraints = {
		fname = { required = true },
		lname = { required = true},
		username = {required=true, size=6-10},
		password = {required=true, size=6-8},
		email = {required=true, type="email"},
		age = {required=true, type="numeric", min=18}
	};
}

 

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
	
	// 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
}

Add Your Comment

Recent Entries

Introducing numeric placeholders in BoxLang source!

Introducing numeric placeholders in BoxLang source!

Introducing Numeric Placeholders in BoxLang

We're excited to announce a new addition to our BoxLang parser—a feature that draws inspiration from several other languages but fits naturally within BoxLang. The conversation around which features from other languages m...

Maria Jose Herrera
Maria Jose Herrera
September 18, 2024
BoxLang 1.0.0 Beta 14 Launched

BoxLang 1.0.0 Beta 14 Launched

In this release, we are excited to introduce several new features and enhancements aimed at improving functionality and user experience. These updates include the creation of immutable query types, new server keys to aid on CLI tooling, and methods to identify runtime initiation modes.

Additionally, we've added an event announcement for dump rendering to enable better integration with external listeners. Read on to learn more about these features and how they can benefit your workflow.

Code Strong!

Luis Majano
Luis Majano
September 13, 2024
Are you attending Adobe CFSummit 2024?

Are you attending Adobe CFSummit 2024?

If you are attending the Adobe ColdFusion Summit 2024, this is what you need to know: As always, Ortus Solutions will be sponsoring this years event as Silver Sponsors, we are excited to meet all the new attendees and old friends of the community of Coldfusion developers

Maria Jose Herrera
Maria Jose Herrera
September 10, 2024