You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -27,27 +27,112 @@ Leverage CommandBox to install:
27
27
28
28
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.
29
29
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`.
// 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
+
30
98
## Mixins
31
99
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
33
101
34
102
```js
35
103
/**
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
0 commit comments