Make input explicit.
Small, strict validation rules with field-level errors and an allowlisted output.
Validate a payload
use Icom\Validation\Validator;
$result = (new Validator())->validate($input, [
'name' => 'required|string|min:2|max:80',
'email' => 'required|email|max:160',
'age' => 'nullable|integer|min:0|max:150',
'role' => 'required|in:reader,editor',
]);
return Response::json($result, $result['valid'] ? 200 : 422);The result
{
"valid": false,
"data": {"name": "Alex"},
"errors": {"email": ["Must be a valid email."]}
}Rules
Available rules: required, nullable, string, integer, boolean, email, min:N, max:N and in:a,b. Integer and boolean rules require actual JSON integers/booleans; there is no implicit coercion. min/max measure integers when an integer rule is present, otherwise Unicode string length. Unknown rules and malformed limits throw configuration errors.
Use only validated values
Unknown input fields are omitted from data. Optional means a field may be absent; null requires nullable. Empty strings still undergo type/length validation unless required rejects them first. Validation is not authorization: enforce access policies before writing data. Nested schemas, file validation and locale-specific rule messages are not part of this release.