PHP Classes
elePHPant
Icontem

File: examples_validate.class.php

Recommend this page to a friend!
  Classes of Sven Wagener  >  validation  >  examples_validate.class.php  >  Download  
File: examples_validate.class.php
Role: Example script
Content type: text/plain
Description: Examples for working with base validation class
Class: validation
Validation with non-regular expression patterns
Author: By
Last change: Corrected comments
Date: 15 years ago
Size: 1,423 bytes
 

 

Contents

Class file image Download
<?
// Create an instance of class validate
$val=new validate();

/**************************************
* NOTE: After instancing class nothing
* is allowed in string. You have
* to allow all step by step
*/

// Letters are allowed
$val->letters_on();

// Numbers are allowed
$val->nums_on();

// Whitespaces are allowed
$val->whitespaces_on();

// Special chars are allowed *~#^$
$val->specialchars_on();

// Punctation marks are allowed .,:;?!()"'
$val->punctations_on();

// Setting length of string (minimum chars=10,maximum chars=150)
$val->length(10,150);

// SQL is allowed
$val->sql_on();

// At last checking string
if($val->check("That's my string")){
   
// String is OK
   
echo "matched\n";
}else{
   
// String is not OK
   
echo "not matched\n";
}

/**************************************
* NOTE: If you use format function, the
* all changes made before will be
* dismissed!!! Only format
* pattern will be used!
*/

// Settung format pattern
$val->format("2N:2N:2N");

// At last checking string
if($val->check("00:00:00")){
   
// String is OK
   
echo "matched\n";
}else{
   
// String is not OK
   
echo "not matched\n";
}

/**************************************
* Example patterns:
* name = 2-20L 2-20L0-1 0-20L0-1 0-20L
* street= 0-30L0-1 0-20L0-1L0-1.1-3N
* phone = 3-6N-3-20N
* ip =1-3N.1-3N.1-3N.1-3N
*
*/
?>