PHP Classes

PTK Validation: Validate values of dates, files and directories

Recommend this page to a friend!
  Info   View files Example   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 134 This week: 1All time: 9,289 This week: 560Up
Version License PHP version Categories
ptk-validation 1.0GNU General Publi...5.3PHP 5, Validation
Description 

Author

This package can validate values of dates, files and directories.

It can perform several types of validation for values that can represent different types of data.

For numbers it can check if the values and within a minimum and maximum, the value is a multiple of a given step value, or is present in a given list of allowed values.

For dates it can check if the date is valid, is withing a minimum or maximum value, or is it in a given valid list of days, months, years, or week days.

For files it can check if the directory is one of valid directories, has one of the allowed permissions, the size is within a minimum and maximum value, the type is one of the allowed types, the file name matches a pattern, the file is executable, a link, is readable or writeable, is an uploaded file, the file name extension is one of the allowed extensions, the MIME type is one of the allowed types.

For directories it can check if the path is a valid directory, it is readable or writeable, the directory is empty.

Picture of Everton da Rosa
  Performance   Level  
Name: Everton da Rosa <contact>
Classes: 17 packages by
Country: Brazil Brazil
Age: 42
All time rank: 78856 in Brazil Brazil
Week rank: 51 Up3 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php

/*
 * Copyright (C) 2014 Everton
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This file is a simple example of use Ptk\utils\Validator for testing an validate strings and numbers.
 */

function show_validation($value, $rules){
    global
$onerror;
    if(\
Ptk\utils\Validator::data($value, $rules, true)){
        echo
"This value $value is VALID.".PHP_EOL;
    }else{
        echo
"This value $value is INVALID.".PHP_EOL;
        echo
"Invalid for: ".PHP_EOL;
       
        echo
join(', ', $onerror);
    }
}

try{
    require
'examples.inc.php';
   
   
//testing numbers
   
$value = 100;
   
$rules = array(
       
'type' => array('integer')//type must be integer
       
,'min' => 0//min value is 0
       
,'max' => 100//max value is 100
   
);
   
show_validation($value, $rules);
   
   
$value = 10.5;
   
$rules = array(
       
'type' => array('integer', 'double')//type must be integer, float or double (for gettype php function, double = float
       
,'min' => 0
       
,'max' => 100
   
);
   
show_validation($value, $rules);
   
   
$value = 21;
   
$rules = array(
       
'type' => array('integer')
        ,
'step' => 5//the value must be multiple of 5
   
);
   
show_validation($value, $rules);
   
   
//testing strings
   
$value = 'PTK is cool!';
   
$rules = array(
       
'type' => array('string')//value must be string
       
,'min' => 5//min lenght of value is 5 char
       
,'max' => 20//maxlenght of value is 20 char
   
);
   
show_validation($value, $rules);
   
   
$value = 'john';
   
$rules = array(
       
'type' => array('string')//value must be string
       
,'list' => array('mary', 'paul', 'john')//value must by one of list (case sensitive)
   
);
   
show_validation($value, $rules);
   
} catch (
Exception $ex) {
    echo
$ex->getMessage();
    exit(
$ex->getCode());
}


  Files folder image Files  
File Role Description
Files folder imageexample (7 files)
Files folder imageptk (1 directory)

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file examples.inc.php Conf. Configuration script
  Accessible without login Plain text file recordset.php Example Example script
  Accessible without login Plain text file recordset_1.php Example Example script
  Accessible without login Plain text file validation_dates.php Example Example script
  Accessible without login Plain text file validation_directory.php Example Example script
  Accessible without login Plain text file validation_files.php Example Example script
  Accessible without login Plain text file validation_string_numbers.php Example Example script

  Files folder image Files  /  ptk  
File Role Description
Files folder imagelib (4 files)

  Files folder image Files  /  ptk  /  lib  
File Role Description
  Plain text file ptk.db.recordset.class_1.php Class Class source
  Plain text file ptk.fs.filefolder.directory.class.php Class Class source
  Plain text file ptk.fs.filefolder.file.class.php Class Class source
  Plain text file ptk.utils.validator.class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 0%
Total:134
This week:1
All time:9,289
This week:560Up