Skip to content

Commit c18bed6

Browse files
committed
completed readme
1 parent 96b3a98 commit c18bed6

File tree

1 file changed

+101
-16
lines changed

1 file changed

+101
-16
lines changed

readme.md

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Apache License, Version 2.0.
1212

1313
- https://github.com/coldbox-modules/cbvalidation
1414
- https://coldbox-validation.ortusbooks.com
15-
- https://forgebox.io/view/validation
15+
- https://forgebox.io/view/cbvalidation
1616

1717
## SYSTEM REQUIREMENTS
1818

1919
- Lucee 5.x+
20-
- Adobe ColdFusion 11+
20+
- Adobe ColdFusion 2016+
2121

2222
## Installation
2323

@@ -27,27 +27,112 @@ Leverage CommandBox to install:
2727

2828
The module will register several objects into WireBox using the `@cbvalidation` namespace. The validation manager is registered as `ValidationManager@cbvalidation`. It will also register several helper methods that can be used throughout the ColdBox application.
2929

30+
## Constraints
31+
32+
Please check out the docs for the latest on constraints: https://coldbox-validation.ortusbooks.com/overview/valid-constraints. Constraints rely on rules you apply to incoming fields of data. They can be created on objects or stored wherever you like, as long as you pass them to the validation methods.
33+
34+
Each property can have one or more constraints attached to it. In an object you can create a `this.constraints` and declare them by the fields you like:
35+
36+
```js
37+
this.constraints = {
38+
39+
propertyName = {
40+
// The field under validation must be yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance.
41+
accepted : any value,
42+
43+
// The field must be alpahbetical ONLY
44+
alpha : any value,
45+
46+
// discrete math modifiers
47+
discrete : (gt,gte,lt,lte,eq,neq):value
48+
49+
// value in list
50+
inList : list,
51+
52+
// max value
53+
max : value,
54+
55+
// Validation method to use in the target object must return boolean accept the incoming value and target object
56+
method : methodName,
57+
58+
// min value
59+
min : value,
60+
61+
// range is a range of values the property value should exist in
62+
range : eg: 1..10 or 5..-5,
63+
64+
// regex validation
65+
regex : valid no case regex
66+
67+
// required field or not, includes null values
68+
required : boolean [false],
69+
70+
// The field under validation must be present and not empty if the `anotherfield` field is equal to the passed `value`.
71+
requiredIf : anotherfield:value,anotherfield:value,...
72+
73+
// The field under validation must be present and not empty unless the `anotherfield` field is equal to the passed
74+
requiredUnless : anotherfield:value,anotherfield:value,...
75+
76+
// same as but with no case
77+
sameAsNoCase : propertyName
78+
79+
// same as another property
80+
sameAs : propertyName
81+
82+
// size or length of the value which can be a (struct,string,array,query)
83+
size : numeric or range, eg: 10 or 6..8
84+
85+
// specific type constraint, one in the list.
86+
type : (ssn,email,url,alpha,boolean,date,usdate,eurodate,numeric,GUID,UUID,integer,string,telephone,zipcode,ipaddress,creditcard,binary,component,query,struct,json,xml),
87+
88+
// UDF to use for validation, must return boolean accept the incoming value and target object, validate(value,target):boolean
89+
udf = variables.UDF or this.UDF or a closure.
90+
91+
// Custom validator, must implement coldbox.system.validation.validators.IValidator
92+
validator : path or wirebox id, example: 'mypath.MyValidator' or 'id:MyValidator'
93+
}
94+
95+
}
96+
```
97+
3098
## Mixins
3199

32-
The module will also register two methods in your handlers/interceptors/layouts/views
100+
The module will also register several methods in your handlers/interceptors/layouts/views
33101

34102
```js
35103
/**
36-
* Validate an object or structure according to the constraints rules.
37-
* @target An object or structure to validate
38-
* @fields The fields to validate on the target. By default, it validates on all fields
39-
* @constraints A structure of constraint rules or the name of the shared constraint rules to use for validation
40-
* @locale The i18n locale to use for validation messages
41-
* @excludeFields The fields to exclude in the validation
42-
* @includeFields The fields to include ONLY in the validation
43-
*
44-
* @return cbvalidation.model.result.IValidationResult
45-
*/
46-
function validateModel()
104+
* Validate an object or structure according to the constraints rules.
105+
*
106+
* @target An object or structure to validate
107+
* @fields The fields to validate on the target. By default, it validates on all fields
108+
* @constraints A structure of constraint rules or the name of the shared constraint rules to use for validation
109+
* @locale The i18n locale to use for validation messages
110+
* @excludeFields The fields to exclude from the validation
111+
* @includeFields The fields to include in the validation
112+
*
113+
* @return cbvalidation.model.result.IValidationResult
114+
*/
115+
function validate()
116+
117+
/**
118+
* Validate an object or structure according to the constraints rules and throw an exception if the validation fails.
119+
* The validation errors will be contained in the `extendedInfo` of the exception in JSON format
120+
*
121+
* @target An object or structure to validate
122+
* @fields The fields to validate on the target. By default, it validates on all fields
123+
* @constraints A structure of constraint rules or the name of the shared constraint rules to use for validation
124+
* @locale The i18n locale to use for validation messages
125+
* @excludeFields The fields to exclude from the validation
126+
* @includeFields The fields to include in the validation
127+
*
128+
* @return The validated object or the structure fields that where validated
129+
* @throws ValidationException
130+
*/
131+
function validateOrFail()
47132

48133
/**
49-
* Retrieve the application's configured Validation Manager
50-
*/
134+
* Retrieve the application's configured Validation Manager
135+
*/
51136
function getValidationManager()
52137
```
53138

0 commit comments

Comments
 (0)