Nested Struct-Array Field Names
Why Use Field Name Shortcuts?
Nested Struct Shorthand
var validationResult = validate(
target = {
"address": {
"streetOne" : "123 Elm Street",
"streetTwo" : "",
"city" : "Anytown",
"state" : "IL",
"zip" : "60606"
}
},
constraints = {
"address": { "required": true, "type": "struct" },
"address.streetOne": { "required": true, "type": "string" },
"address.streetTwo": { "required": false, "type": "string" },
"address.city": { "required": true, "type": "string" },
"address.state": { "required": true, "type": "string", "size": 2 },
"address.zip": { "required": true, "type": "numeric", "size": 5 }
}
);Array Validation Shortcuts
Simple Array Validation
Array of Structs
Complex Nested Arrays
Combined Struct and Array Examples
User Profile with Multiple Addresses
E-commerce Order Structure
Error Message Context
Best Practices
1. Use Descriptive Field Names
2. Group Related Constraints
3. Validate Array Container and Items
Common Use Cases
API Request Validation
Form Data Processing
Configuration Validation
Last updated
Was this helpful?