Documentation
Validator

For data validation we have developed a composer package called Validator (opens in a new tab) You can use validator in controller and service classes very easily to validate data.

Example

$validate = $this->validate( [
	'email' => 'required|email',
	'password' => 'required|min:8'
	'username' => 'required|min:3|max:15|stringOnly'
] );
 
$error = $validator->error();
if ($error) {
	return $error;
}
$data = $validator->getData();

Available Rules

RuleDescription
requiredCheck if the field under validation is present in the input data and is not empty.
emailCheck if the field under validation is valid email address.
urlCheck if the field under validation is valid url.
stringCheck if the field under validation is string.
stringOnlyCheck if the field under validation is only string characters.
stringWithSpaceCheck if the field under validation is string with space.
stringWithNumberCheck if the field under validation is string with number.
StringWithDashCheck if the field under validation is string with dash and underscore.
minCheck if the field under validation is greater than or equal to the given value.
maxCheck if the field under validation is less than or equal to the given value.
integerCheck if the field under validation is integer.
sameValueCheck if the field under validation is same as the given value.