Different Validator

This validator can be used to ensure that the given field under validation must have a different value than another specified field.

Back to Validators List

Usage

There are two different ways in which all Sparta validators can be used. See below examples for more explanations:

Example #1:

You can simply instantiate the Different validator and pass to it the data that you want to validate.

<?php
use Sparta\Validators\Different;

$validator = Different(['from' => 'coderavine@gmail.com']);

if(!$validator->isValid('myemail@gmail.com')){ 
    //handle errors
}

Example #2:

You can build your validation rules and pass it to the Validation object to handle as shown below:

<?php
use Sparta\Validation;
$data = ['blockedEmail' => 'coderavine@gmail.com'];

$rules = [
    'email' => 'different:from=blockedEmail',
];

$validation = new Validation($data, $rules);
if(!$validation->isValid()){
    //handle errors
}

In case of validation failure, error messages can be retrieved using the getErrors method.

Back to Validators List