eclemens/php-validation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eclemens/php-validation

最新稳定版本:0.1.2

Composer 安装命令:

composer require eclemens/php-validation

包简介

PHP Validation class inspired by the jQuery Validation Plugin

README 文档

README

PHP Validation class inspired by the jQuery Validation Plugin (http://jqueryvalidation.org/)

Description

I created this library to use along with jQuery Validation Plugin.

It allows to use the same (or similar) rules used for jQuery Validation Plugin implementation in the client side to validate the request in the server side.

Installation

Install using composer. Exists as eclemens/php-validation in the packagist repository.

Add the package to the require section in your composer.json file:

{
    "require" : {
        "eclemens/php-validation": "dev-master"
    }
}

Usage

Basic standalone usage

PHP

<?php

require_once __DIR__ . '/vendor/autoload.php';

// Create validator instance
$validator = new PHPValidation\Validation();

// Add rules
$validator->rules([
    'username'   => ['required' => true, 'rangelength' => [3, 64]],
    'email'      => ['required' => true, 'email' => true],
    'password'   => ['required' => true],
    'repassword' => ['equalTo' => 'password']
]);

// Data
$data = [
    'username'   => 'johndoe',
    'email'      => 'johndoe@example.org',
    'password'   => 'pass1234',
    'repassword' => 'pass1234'
];

// Validate:
if ($validator->valid($data)) {
    // It's a valid data!
}

Usage along with jQuery Validation Plugin

HTML

<form>
    <input type="text" name="username">
    <input type="email" name="email">
    <input type="password" name="password">
    <input type="repassword" name="repassword">
    <input type="submit" name="submit">
</form>

JavaScript

$("form").validate({
    "rules": {
        "username":   {"required": true, "rangelength": [3, 64]},
        "email":      {"required": true, "email": true},
        "password":   {"required": true},
        "repassword": {"equalTo": "[name=password]"}
    }
});

PHP

<?php

require_once __DIR__ . '/vendor/autoload.php';

// Create validator instance
$validator = new PHPValidation\Validation();

// Add rules
$validator->rules([
    'username'   => ['required' => true, 'rangelength' => [3, 64]],
    'email'      => ['required' => true, 'email' => true],
    'password'   => ['required' => true],
    'repassword' => ['equalTo' => 'password'],
]);

// Validate:
if ($validator->valid($_REQUEST)) {
    // It's a valid data!
}

TODO

  • Missing additional rules
  • i18n

统计信息

  • 总下载量: 232
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-21