VALIDATION
CBVALIDATION is a powerful and flexible module that simplifies the validation of incoming data in your ColdBox applications (install cbvalidation). With its easy-to-use API and comprehensive set of validation rules, ColdBox Validation makes it simple to ensure that the data submitted by your users is correct and valid.
It comes with over 30 different validation constraints, and it is completely customizable to fit your validation needs. It even supports localized messages in any language via our cbi18n module.
install cbvalidation
Define Reusable 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}
};
}
Validate Easily
any function saveShared( event, rc, prc ){
// validation
validate(
target = rc,
constraints = "sharedUser"
).onError( function( results ){
flash.put(
"notice",
results.getAllErrors().tostring()
);
return index( event, rc, prc )
})
.onSuccess( function( results ){
flash.put( "User info validated!" )
relocate( "main" )
} );
}
You can read more about ColdBox Validation in the documentation .