Git Product home page Git Product logo

fastvalidator's Introduction

FastValidator

The php Validation classes are based on Respect\Validation

单参数Example

$result = FastValidator::stringVal("lai", [
    'rule'    => 'string',
    'require' => true,
    'length'  => [3, 30],
    'regex'   => '/^[a-z0-9]{1}[a-z0-9@\.]+$/',
    'name'    => '用户名',
    'msg'     => '{{name}} 必须由字母、数字、@、.组成,长度限制为3到30个字符串!'
]);

以上示例以 json 会输出:

{
    "ok": true,
    "error": null,
    "val": "lai"
}

单参数实例 2 :

FastValidator::Validator("laixyz", ['rule' => 'email']);

以上示例以 json 会输出

{
    "ok": false,
    "error": "All of the required rules must pass for \"laixyz\"",
    "val": ""
}

多参数实例

$values = [
    'user'     => '[email protected]',
    'password' => 'abcd',
    'email'    => 'ok'
];
$rules  = [
    'user'     => [
        'rule'    => 'string',
        'require' => true,
        'length'  => [3, 30],
        'regex'   => '/^[a-z0-9]{1}[a-z0-9@\.]+$/',
        'name'    => '用户名',
        'msg'     => '{{name}} 必须由字母、数字、@、.组成,长度限制为3到30个字符串!'
    ],
    'password' => [
        'rule'    => 'string',
        'require' => true,
        'length'  => [6, 32],
        'name'    => '密码',
        'msg'     => '{{name}} 的长度限制为6到32个字符串!'
    ],
    'email'    => [
        'rule' => 'email',
        'name' => 'email'
    ],
    'gender'   => [
        'rule'    => 'int',
        'in'      => [0, 1, 2],
        'require' => true
    ]
];
$result = FastValidator::ValidatorAll($values, $rules);

以上示例以 json 会输出:

{
    "password": {
        "ok": false,
        "error": "密码 的长度限制为6到32个字符串!",
        "val": "abcd"
    },
    "email": {
        "ok": false,
        "error": "All of the required rules must pass for email",
        "val": "ok"
    },
    "gender": {
        "ok": false,
        "error": "All of the required rules must pass for gender",
        "val": null
    }
}

fastvalidator's People

Contributors

laixyz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.