2017 © Pedro Peláez
 

library php-validation

PHP Validation class inspired by the jQuery Validation Plugin

image

eclemens/php-validation

PHP Validation class inspired by the jQuery Validation Plugin

  • Tuesday, October 6, 2015
  • by eclemens
  • Repository
  • 1 Watchers
  • 2 Stars
  • 47 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

php-validation

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

Description

I created this library to use along with jQuery Validation Plugin., (*2)

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., (*3)

Installation

Install using composer. Exists as eclemens/php-validation in the packagist repository., (*4)

Add the package to the require section in your composer.json file:, (*5)

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

Usage

Basic standalone usage

PHP, (*6)

<?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, (*7)

<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, (*8)

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

PHP, (*9)

<?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

The Versions

06/10 2015

dev-master

9999999-dev https://github.com/eclemens/php-validation

PHP Validation class inspired by the jQuery Validation Plugin

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Eduardo Clemens

validator validation jquery-validation php-validation

06/10 2015

0.1.2

0.1.2.0 https://github.com/eclemens/php-validation

PHP Validation class inspired by the jQuery Validation Plugin

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Eduardo Clemens

validator validation jquery-validation php-validation

30/04 2015

v0.1.1

0.1.1.0 https://github.com/eclemens/php-validation

PHP Validation class inspired by the jQuery Validation Plugin

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Eduardo Clemens

validator validation jquery-validation php-validation

22/04 2015

0.1.0

0.1.0.0 https://github.com/eclemens/php-validation

PHP Validation class inspired by the jQuery Validation Plugin

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Eduardo Clemens

validator validation jquery-validation php-validation