Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple ValidationKit for PHP
C PHP
Tree: d6d1e3b3ef

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/ValidationKit
tests
LICENSE
README.md
build.xml
package.ini
package.xml
phpdox.xml
phpunit-ci.xml
phpunit.xml

README.md

Validation

Validators

  • ValidationKit\PhoneNumber\TWPhoneNumberValidator
  • ValidationKit\TW\IDNumberValidator
  • ValidationKit\CallbackValidator
  • ValidationKit\ChainedValidator
  • ValidationKit\EmailValidator
  • ValidationKit\PasswordValidation
  • ValidationKit\PatternValidator
  • ValidationKit\RangeValidator
  • ValidationKit\StringLengthValidator
  • ValidationKit\StringValidator

Validator Constructor

ValidationKit Validator's constructor prototype is:

__construct( $options = array() , $msgs = array() );

The $msgs() is an associative array that contains:

msg_id => msg_str

For different kind of validation message, validator provides its custom msgid for message mapping, you can simply override the message dictionary to customize your messages.

EmailValidator

<?php
use ValidationKit\EmailValidator;
$validator = new EmailValidator;
if( $validator->validate('foo@foo.com') ) {
    echo "Success!\n";
} else {
    foreach( $validator->getMessages() as $msgId => $msg ) {
        // $msg is a ValidationMessage object, 
        // which supports __toString() convertion.
        echo $msg . "\n";
    }
}

PatternValidator

<?php
    use ValidationKit\PatternValidator;
    $validator = new PatternValidator( '#test test test#' );
    $bool = $validator->validate( $value );
    $msgs = $validator->getMessages();

StringLengthValidator

<?php
$validator = new ValidationKit\StringLengthValidator(array( 
    'min' => 5, 'max' => 10,
));

StringValidator

<?php
    use ValidationKit\StringValidator;
    $validator = new StringValidator(array( 
            'starts_with' => '....' , 
            'ends_with' => ... ,
            'is' => ...,
            'contains' => ...,
            'except' => ...,
        ), array( 
            'invalid' => 'general invalid message',
            'starts_with_error' => 'error message'
        ));
    $bool = $validator->validate( $string );
    $msgs  = $validator->getMessages();
    foreach( $msgs as $msgId => $msg ) {
        echo $msg, "\n";
    }

RangeValidator

<?php
    use ValidationKit\RangeValidator;
    $validator = new RangeValidator(array(
        'greater_than' => 100,
        'less_than' => 200,
    ));
    $bool = $validator->validate( 200 );

    $validator = new RangeValidator(array( '>' => 10 , '<' => 200 ));
    $bool = $validator->validate( 10.0 );

Hacking

Install dependencies:

$ onion install

Run unit tests:

$ phpunit
Something went wrong with that request. Please try again.