use Valitron\Validator; $v = new Validator($_POST); $v->addRule('required', 'username'); if ($v->validate()) { // proceed with login process } else { // display error messages }
use Valitron\Validator; $v = new Validator($_POST); $v->addRule('customRule', function($field, $value, array $params, array $fields) { $customField = $fields[$params[0]]; if ($value == $customField) { return true; } return false; }, 'The :field field does not match the :customField field'); $v->rule('email', 'email'); $v->rule('customRule', 'verifyEmail', ['email']); if ($v->validate()) { // proceed with registration process } else { // display error messages }In this example, we create a custom validation rule called 'customRule' which compares the value of 'verifyEmail' field with the value of 'email' field. If they do not match, we display an error message to the user. Note: Custom rules can also be added as standalone classes and then registered with the Valitron library using the addInstanceRule method.