Just wondering if there was merit in looking at a wholistic validation approach in lucee, so that custom validations could be created with ease and used across the engine. I realise this may be a massive undertaking, but would yield massive rewards. I get that you can use regex to achieve some of this, but that makes code ugly.
Anyway an idea can’t hurt.
There are some things I can see that need consideration here:
- How validation is currently handled
- Consideration for Locale-specific context (aka en_us, en_uk, en_au)
- Potential for integration technique to be reused for other integrations
For example
arrayOfTenNumbers.cfs
dropped into new ‘validators’ directory sibling of functions, tag dir, or could be implemented as an extension of type ‘validator’ and subtype ‘array’ (each item of array has to have a length of 10 numbers)
would integrate as:
- isValid:
isValid('arrayOfTenNumbers',value)
- Member Function
myarray.isArrayOfTenNumbers()
- would validate database types:
{ numbers : { value="#myArrayOfTenNumbers#", type:"arrayOfTenNumbers" } }
and also new function typeOf
typeOf(myArrayOfTenNumbers)
would return “arrayOfTenNumbers” and would validate in as an array (simple mode) AND arrayOfTenNumbers (complex mode)
complex mode of typeOf could also return “array,arrayOfIntegers,arrayOfTenNumbers” in this case also.
Example 2:
arrayofuuids.cfs
- type
- min (integer) = 0 (optional)
- max (integer) = 1000000000000000 (optional)
allows an array of type (integer,array,struct,date,etc) with min/max length of array
which creates:
`isValid(‘arrayof’,value,type,min,max)
#discuss
like interface could have it’s own component type?!
validator extends="arrayOf" {
// add extra sub-validators for arrayof type to add uuid to the existing list of validators
private boolean function uuids() {
// logic to prove is a uuid
return true;
}
}