PHP code example of cloudonaut / validator

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

    

cloudonaut / validator example snippets



use Cloudonaut\Lib\Validator;
$validator = new Validator();


use Cloudonaut\Lib\Validator;
$validator = new Validator();

$value = "";
$msg = "Value can't be empty";
$validator->isNotEmpty($value, $msg);
if ($validator->hasViolations())
{
    implode("," $validator->getViolations());
}

$value = 8;
$msg = "Value must be 7";
if ($value != 7)
{
    $validator->addViolation($msg);
}

if ($validator->hasViolations())
{
    implode("," $validator->getViolations());
}

$name = "R2D2"; // wrong name
$mail="test.example.com"; //wrong mail

$validator->isNotEmpty($name, "Name can't be empty");
$validator->isNotEmpty($mail, "Mail can't be empty");
$validator->isTextOnly($name, "Name can't have numbers");
$validator->isEmail($name, "Mails is not in the correct format");

if ($validator->hasViolations())
{
    implode(", " $validator->getViolations());
}