yandjin/custom-validation

受 Laravel 验证启发的轻量级验证包,无依赖

v1.0 2020-03-05 11:55 UTC

This package is not auto-updated.

Last update: 2024-09-28 09:45:56 UTC


README

如何安装

composer require yandjin/custom-validation

如何使用

使用以下命名空间

use YanDjin\Validation\CustomValidation;

验证返回 true 或 false

$arrayOfData = [
    "name" => "YanDjin",
    "age" => 26
];

if(!CustomValidation::validateData($arrayOfData, [
    "name" => "characters",
    "age" => "numeric|min:18" // pipe the validation rules (: for parameters ) or use array "age" => ["numeric", "min" => 18]
]) {
    // returns the fields not passing the validation and the errors
    return CustomValidation::getErrorsMessagesAsString();
}