Giter Club home page Giter Club logo

validation's Introduction

Build Status Total Downloads Latest Stable Version

Validation (Laravel Package)

"The power of 'Respect Validation' on Laravel"

Version Compatibility

Laravel kennedytedesco/validation
5.4.x "kennedytedesco/validation": "~4.0"
5.3.x "kennedytedesco/validation": "~3.0"
5.2.x "kennedytedesco/validation": "~3.0"
5.1.x "kennedytedesco/validation": "~2.0"
5.0.x "kennedytedesco/validation": "~2.0"
4.2.x "kennedytedesco/validation": "~1.0"
4.1.x "kennedytedesco/validation": "~1.0"
4.0.x "kennedytedesco/validation": "~1.0"

Installation

Put the following in your composer.json file:

{
    "require": {
        "kennedytedesco/validation": "~3.0"
    }
}

Run the Composer update comand:

composer update

In your config/app.php add 'KennedyTedesco\Validation\ValidationServiceProvider' to the end of the 'providers' array:

'providers' => array(
    ...
    ...
    'KennedyTedesco\Validation\ValidationServiceProvider',
),

Supported rules (with examples)

// Rules
$rules = array(
    'cpf'               => 'cpf',
    'cnpj'              => 'cnpj',
    'cnh'               => 'cnh',
    //'minimumAge'        => 'minimumAge:20',
    'callback'          => 'callback:is_int',
    'charset'           => 'charset:ASCII',
    'consonant'         => 'consonant',
    'vowel'             => 'vowel',
    'alnum'             => 'alnum:-',
    'digit'             => 'digit',
    'alpha'             => 'alpha',
    'containsArray'     => 'contains:banana',
    'contains'          => 'contains:banana',
    'countryCode'       => 'countryCode',
    'creditCard'        => 'digit|creditCard',
    'domain'            => 'domain',
    'directory'         => 'directory',
    'fileExists'        => 'fileExists',
    'isFile'            => 'file',
    'endsWith'          => 'endsWith:banana',
    'equals'            => 'equals:banana',
    'even'              => 'even',
    'floatVal'          => 'floatVal',
    'graph'             => 'graph',
    'instance'          => 'instance:DateTime',
    'int'               => 'int',
    'json'              => 'json',
    'leapDate'          => 'leapDate:Y-m-d',
    'leapYear'          => 'leapYear',
    'arrayVal'          => 'arrayVal',
    'lowercase'         => 'lowercase',
    'macAddress'        => 'macAddress',
    'multiple'          => 'multiple:3',
    'negative'          => 'negative',
    'noWhitespace'      => 'noWhitespace',
    'nullValue'         => 'nullValue',
    'numeric'           => 'numeric',
    'objectType'        => 'objectType',
    'odd'               => 'odd',
    'perfectSquare'     => 'perfectSquare',
    'positive'          => 'positive',
    'primeNumber'       => 'primeNumber',
    'punct'             => 'punct',
    'readable'          => 'readable',
    'regex'             => 'regex:/5/',
    'roman'             => 'roman',
    'slug'              => 'slug',
    'space'             => 'space:b',
    'tld'               => 'tld',
    //'uploaded'          => 'uploaded',
    'uppercase'         => 'uppercase',
    'version'           => 'version',
    'xdigit'            => 'xdigit',
    'writable'          => 'writable',
    'alwaysValid'       => 'alwaysValid',
    'boolType'          => 'boolType',
    'youtube'           => 'videoUrl:youtube',
    'vimeo'             => 'videoUrl:vimeo',
    'video1'            => 'videoUrl',
    'video2'            => 'videoUrl',
);

// Data
$data = array(
    'cpf'               => '22205417118',
    'cnpj'              => '68518321000116',
    'cnh'               => '02650306461',
    //'minimumAge'        => '10/10/1990',
    'callback'          => 20,
    'charset'           => 'acucar',
    'consonant'         => 'dcfg',
    'vowel'             => 'aeiou',
    'alnum'             => 'banana-123 ',
    'digit'             => '120129  21212',
    'alpha'             => 'banana',
    'containsArray'     => ['www', 'banana', 'jfk', 'http'],
    'contains'          => 'www banana jfk http',
    'countryCode'       => 'BR',
    'creditCard'        => '5555666677778884',
    'domain'            => 'google.com.br',
    'directory'         => __DIR__,
    'fileExists'        => __FILE__,
    'file'              => __FILE__,
    'endsWith'          => 'pera banana',
    'equals'            => 'banana',
    'even'              => 8,
    'floatVal'          => 9.8,
    'graph'             => 'LKM@#$%4;',
    'instance'          => new Datetime(),
    'int'               => 9,
    'json'              => '{"file":"laravel.php"}',
    'leapDate'          => '1988-02-29',
    'leapYear'          => '1988',
    'arrayVal'          => ['Brazil'],
    'lowercase'         => 'brazil',
    'macAddress'        => '00:11:22:33:44:55',
    'multiple'          => '9',
    'negative'          => '-10',
    'noWhitespace'      => 'laravelBrazil',
    'nullValue'         => null,
    'numeric'           => '179.9',
    'objectType'        => new stdClass(),
    'odd'               => 3,
    'perfectSquare'     => 25,
    'positive'          => 1,
    'primeNumber'       => 7,
    'punct'             => '&,.;[]',
    'readable'          => __FILE__,
    'regex'             => '5',
    'roman'             => 'VI',
    'slug'              => 'laravel-brazil',
    'space'             => '              b      ',
    'tld'               => 'com',
    //'uploaded'          => 'path to file',
    'uppercase'         => 'BRAZIL',
    'version'           => '1.0.0',
    'xdigit'            => 'abc123',
    'writable'          => __FILE__,
    'alwaysValid'       => '@#$_',
    'boolType'          => is_int(2),
    'youtube'           => 'http://youtu.be/l2gLWaGatFA',
    'vimeo'             => 'http://vimeo.com/33677985',
    'video1'            => 'https://youtu.be/l2gLWaGatFA',
    'video2'            => 'https://vimeo.com/33677985',
);

// Make the validation
$validator = \Validator::make($data, $rules);

// Result
if( $validator->fails() )
{
    // Print errors
    $messages = $validator->messages();
    foreach ($messages->all() as $message) {
        echo '<li>'.$message.'</li>';
    }
}
else
{
    // Success
    echo 'True.';
}

Respect Validation

For more details about the available rules:

http://respect.github.io/Validation/docs/validators.html

Repository of Respect Validation:

https://github.com/Respect/Validation

validation's People

Contributors

kennedytedesco avatar ricardogobbosouza avatar henriquemoody avatar icetee avatar

Watchers

James Cloos avatar madeny 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.