procedural data validation for PHP

Download .zip Download .tar.gz View on GitHub

Build Status Coverage Status

"I find your lack of validation... disturbing." -- Darth Validator

DARTH is a very simple procedural data validation tool for PHP. Just create a stack of rules, and apply them to your data hash.

DARTH supports the following validation types:

  • required
  • email
  • confirmation
  • regex
  • custom callbacks


The example below shows all that you can do with this.

require __DIR__."/darth.php";

# create a stack of rules to apply
$rules = array(
  darth\rule('required', 'username', 'Username is empty'),
  darth\rule('regex', 'username', '/^[a-z0-9_]{4,}$/i', 'Username is invalid'),
  darth\rule('required', 'email', 'Email is empty'),
  darth\rule('email', 'email', 'Email is invalid'),
    'Password is invalid or not confirmed'
    'Age is invalid'
    function ($role) { return $role == 'sith'; },
    'Come to the dark side!'

# sample data that needs validation
$data_fail = array(
  'username' => '',
  'email' => '',
  'role' => 'developer',
  'password' => 'abc',
  'password_confirmation' => '123'

# apply the rules, and get the errors
$errors = darth\apply($rules, $data_fail);


Output will be:

array(5) {
  array(2) {
    string(17) "Username is empty"
    string(19) "Username is invalid"
  array(2) {
    string(14) "Email is empty"
    string(16) "Email is invalid"
  array(1) {
    string(36) "Password is invalid or not confirmed"
  array(1) {
    string(14) "Age is invalid"
  array(1) {
    string(22) "Come to the dark side!"


MIT http://noodlehaus.mit-license.org