GithubHelp home page GithubHelp logo

h2lsoft / validator Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 47 KB

A library of validators values in multilanguage with CSRF protection

License: MIT License

PHP 100.00%
php form validator data csrf csrf-protection

validator's Introduction

Validator

A library for string validators values in multilanguage.

Version

Installation

Install directly via Composer:

$ composer require h2lsoft/validator

Basic Usage

// simulate POST
$_POST['name'] = 'the king !';
$_POST['email'] = 'fa@email';
$_POST['zip_code'] = 'a2345';
$_POST['choices'] = ['apple'];
$_POST['job'] = 'webdesigner';
$_POST['days'] = '-50';
$_POST['date'] = '31/20/2020';
$_POST['datetime'] = '31/20/2020 12:00';
$_POST['website'] = 'text.com';
$_POST['regex_test'] = 'abcdef';
$_POST['conditions'] = 0;

// rules
$validator = new \h2lsoft\Data\Validator('en'); // `en` by default but you can change it
$validator->input('name')->required()->alpha(' '); // space allowed
$validator->input('email', "email address")->required()->email();
$validator->input('zip_code', 'zip code')->required()->mask('99999');
$validator->input('choices')->required()->multiple()->in(['banana', 'pear'])->minLength(2);
$validator->input('job')->required()->equal('CEO');
$validator->input('days')->required()->integer()->between(1, 60);
$validator->input('date')->date('m/d/Y');
$validator->input('datetime')->required()->datetime('m/d/Y H:i');
$validator->input('website')->url(FILTER_FLAG_PATH_REQUIRED);
$validator->input('regex_test')->regex("/^x/i", "`[FIELD]` must start by x");
$validator->input('conditions')->required()->accepted();

if($validator->fails())
{
	print_r($validator->result());
}
else
{
	die("No error detected");
}

Rules

Strings

  • required
  • email
  • mask
  • in
  • notIn
  • integer
  • float
  • min
  • max
  • between
  • length
  • minLength
  • maxLength
  • equal
  • accepted
  • url
  • alpha
  • alphaNumeric
  • date
  • datetime
  • regex
  • ip
  • sameAs
  • requiredIf

Array (checkboxes, select multiple)

  • multiple
  • between
  • min
  • max

Files

  • fileRequired
  • fileMaxSize
  • fileExtension
  • fileMime
  • fileImage
  • fileImageBase64

Customisation

  • addLocalMessages
  • setInputNames (array)
  • setInputName
  • addError (custom error)

More information see examples directory

License

MIT. See full license.

validator's People

Contributors

h2lsoft avatar

Stargazers

 avatar

Watchers

 avatar

validator's Issues

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.