Validation Class

The Validation class is a stand-alone library, which in terms means that it does not actually requires any other to function. The usage of this class is to validate data.

Quick Example

We are validating a string to with the Validation::is_alnum method, to ensure that the data only consist of alpha-numerical characters.

  1. // Initiate main class
  2. $Input = new Input;
  3.  
  4. $name = $Input->get ('name');
  5.  
  6. if ($Input->validate ('is_alnum', $name->value())) {
  7. // 'name' is now validated as an alpha-numerical string
  8. }

Stand-alone Example

This example shows how to validate data if you do not use the Input class.

  1. // Initiate Validation class
  2. $Validate = new Validate;
  3.  
  4. $data = 'abc1234%';
  5.  
  6. if ($Validate->is_alnum ($data) ) {
  7. echo 'Success!';
  8. } else {
  9. echo 'Failure!';
  10. }

As you might see – it will return FALSE as $data contains a non-alpha-numerical character (%).

Methods

validation.txt · Last modified: 2010/07/22 17:27 by davids
Back to top
CC Attribution-Share Alike 3.0 Unported
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0