PHP code example of ej3dev / veritas

1. Go to this page and download the library: Download ej3dev/veritas 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/ */

    

ej3dev / veritas example snippets


// Is $var a decimal value in the interval [-1,1]?
v::is($var)->dec()->in('[-1,1]')->verify();

// Is $var an array with a index 8 with value 'eight'?
v::is($var)->arr()->key(8,'eight')->verify();

// Is $var a string that represent a date in format year-month-day?
v::is($var)->str()->date('Y-m-d')->verify();

// Is $var an object with a property called 'name'?
v::is($var)->obj()->attr('name')->verify();

//Is $mail a valid email address from Gmail or Yahoo?
v:isEmail($mail)->contains('@gmail','@yahoo')->verify(); 




//Composer autoloader


//Single file to/Verifier.php');

//Your code
//...

use ej3dev\Veritas\Verifier as v;

v::is($var);  //Created new instance loaded with $var data

v::is($var)->int()->in('[0,9]'); //Add rules to verify an integer between 0 and 9

$result = v::is($var)->int()->in('[0,9]')->verify(); //Run tests and get true or false
//If $var=8 then $result=true
//If $var=10 then $result=false  


//Composer autoload
er as v;

$hello = 'Hello World!';
//Is $hello a string?
v::is($hello)->str()->verify(); //true

$number = 8;
//Is $number an integer verify(); //true
//Is $number a integer /Is $decimal a decimal number in the close interval [1,5]?
v::is($decimal)->dec()->in('[1,5]')->verify(); //true
//Is $decimal a decimal number in the open interval (-1,1)?
v::is($decimal)->dec()->in('(-1,1)')->verify(); //false

$value = 'two';
//Is $value a string 

$pi = 3.1416;
$euler = 2.7183

//Default
v::is($pi)->ineq('>',$euler)->verify(); //Return: true
v::is($pi)->eq($euler)->verify(); //Return: false

//One parameter
v::is("8")->str()->num()->verify(
	'String with numeric value'
); //Return: 'String with numeric value'
v::is("eight")->str()->num()->verify(
	'String with numeric value'
); //Return: false

//Two parameters
v::is($pi)->in('[3.14,3.142)')->verify(
	'Number too close to pi',
	'This number is not pi'
); //Return: Number too close to pi
v::is($euler)->in('[3.14,3.142)')->verify(
	'Number too close to pi',
	'This number is not pi'
); //Return: This number is not pi

$email = '[email protected]';
v::isEmail($email)->verify(
	function($email) { mail($email,'Hello','Lorem ipsum dolor sit amet...'); },
	function() { exit('Error: Invalid email address'); }
);


$number = 8;
v::is($number)->int()->verify(); //true
v::is($number)->notInt()->verify(); //false
v::is($number)->dec()->verify(); //false
v::is($number)->notDec()->verify(); //true

$pi = 3.14;
v::is($pi)->in('[-1,1]')->verify(); //false
v::is($pi)->notIn('[-1,1]')->verify(); //true
v::is($pi)->ineq('<=',3.0)->verify(); //false
v::is($pi)->notIneq('<=',3.0)->verify(); //true