PHP code example of maplephp / validate

1. Go to this page and download the library: Download maplephp/validate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maplephp / validate example snippets


use MaplePHP\Validate\Inp;

// Validate option 1
$inp = new Inp("Lorem ipsum dolor");
var_dump($inp->length(1, 200)); // true

// Validate option 2
$valid = Inp::value("Lorem ipsum dolor")->length(1, 200);
var_dump($valid); // true

Inp::value("Lorem ipsum dolor")->

Inp::value(0)->hasValue();

Inp::value("Lorem ipsum dolor")->length(1);

Inp::value("Lorem ipsum dolor")->length(1, 160);

Inp::value("Lorem ipsum dolor")->equalLength(10);

Inp::value("Lorem ipsum dolor")->equal("Lorem ipsum dolor");

Inp::value("Lorem ipsum dolor")->notEqual("Lorem ipsum");

Inp::value("[email protected]")->email();

Inp::value("+46709676040")->phone();

Inp::value("198808213412")->socialNumber();

Inp::value("197511043412")->orgNumber();

Inp::value("1616523623422334")->creditCard();

Inp::value("SE8272267913")->vatNumber();

Inp::value("3.1415")->isFloat();

Inp::value("42")->isInt();

Inp::value("42")->number();

Inp::value("20")->positive();

Inp::value("-20")->negative();

Inp::value("1.0.0")->validVersion(true); // strict semantic versioning

Inp::value("1.0.0")->versionCompare("2.0.0", '>=');

Inp::value("password123")->lossyPassword(8);

Inp::value("Password#123!")->strictPassword(8);

Inp::value("HelloWorld")->atoZ();

Inp::value("helloworld")->lowerAtoZ();

Inp::value("HELLOWORLD")->upperAtoZ();

Inp::value("#000000")->hex();

Inp::value("2022-02-13")->date("Y-m-d");

Inp::value("2022-02-13 14:15")->dateTime("Y-m-d H:i");

Inp::value("14:15")->time("H:i");

Inp::value("1988-05-22")->age(18);

Inp::value("example.com")->domain();

Inp::value("https://example.com/page")->url();

Inp::value("example.com")->dns();

Inp::value("/path/to/file.txt")->isFile();

Inp::value("/path/to/directory")->isDir();

Inp::value("/path/to/file.txt")->isWritable();

Inp::value("/path/to/file.txt")->isReadable();

Inp::value("12345")->zip(5);

Inp::value("abc")->pregMatch("a-zA-Z");

Inp::value([1, 2, 3])->isArray();

Inp::value($obj)->isObject();

Inp::value($resource)->isResource();

Inp::value(true)->isBool();

Inp::value("yes")->isBoolVal();

Inp::value("12345")->oneOf(['isInt' => []]);

Inp::value("12345")->allOf(['isInt' => [], 'length' => [5]]);