Source for file Valid.php
Documentation is available at Valid.php
* DB_Table class for constants and other globals.
require_once 'DB/Table.php';
* validation ranges for integers
if (! isset ($GLOBALS['_DB_TABLE']['valid'])) {
$GLOBALS['_DB_TABLE']['valid'] = array (
'smallint' => array (pow(-2 , 15 ), pow(+2 , 15 ) - 1 ),
'integer' => array (pow(-2 , 31 ), pow(+2 , 31 ) - 1 ),
'bigint' => array (pow(-2 , 63 ), pow(+2 , 63 ) - 1 )
* DB_Table_Valid validates values against DB_Table column types.
* $Id: Valid.php,v 1.3 2004/07/10 15:07:55 pmjones Exp $
* @author Paul M. Jones <pmjones@ciaweb.net>
* Check if a value validates against the 'boolean' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
if ($value === true || $value === false ) {
} elseif (is_numeric($value) && ($value == 0 || $value == 1 )) {
* Check if a value validates against the 'char' and 'varchar' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
function isChar($value, $colsize)
$in_range = (strlen($value) <= $colsize);
* Check if a value validates against the 'smallint' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
($value >= $GLOBALS['_DB_TABLE']['valid']['smallint'][0 ]) &&
($value <= $GLOBALS['_DB_TABLE']['valid']['smallint'][1 ]);
* Check if a value validates against the 'integer' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
($value >= $GLOBALS['_DB_TABLE']['valid']['integer'][0 ]) &&
($value <= $GLOBALS['_DB_TABLE']['valid']['integer'][1 ]);
* Check if a value validates against the 'bigint' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
($value >= $GLOBALS['_DB_TABLE']['valid']['bigint'][0 ]) &&
($value <= $GLOBALS['_DB_TABLE']['valid']['bigint'][1 ]);
* Check if a value validates against the 'decimal' data type.
* For the column defined "DECIMAL(5,2)" standard SQL requires that
* the column be able to store any value with 5 digits and 2
* decimals. In this case, therefore, the range of values that can be
* stored in the column is from -999.99 to 999.99. DB_Table attempts
* to enforce this behavior regardless of the RDBMS backend behavior.
* @param mixed $value The value to validate.
* @param string $colsize The 'size' to use for validation (to make
* sure of min/max and decimal places).
* @param string $colscope The 'scope' to use for validation (to make
* sure of min/max and decimal places).
* @return boolean True if the value is valid for the data type, false
function isDecimal($value, $colsize, $colscope)
// maximum number of digits allowed to the left
// and right of the decimal point.
$left_max = $colsize - $colscope;
// ignore negative signs in all validation
// find the decimal point, then get the left
$left = substr($value, 0 , $pos);
$right = substr($value, $pos+1 );
// how long are the left and right portions?
// do the portions exceed their maxes?
if ($left_len > $left_max ||
$right_len > $right_max) {
// one or the other exceeds the max lengths
// both are within parameters
* Check if a value validates against the 'single' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
* Check if a value validates against the 'double' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
* Check if a value validates against the 'time' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
* Check if a value validates against the 'date' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
if (strlen($value) != 10 || $s1 != '-' || $s2 != '-' ||
* Check if a value validates against the 'timestamp' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
$date = substr($value, 0 , 10 );
$time = substr($value, 11 , 8 );
if (strlen($value) != 19 || $sep != ' ' ||
* Check if a value validates against the 'clob' data type.
* @param mixed $value The value to validate.
* @return boolean True if the value is valid for the data type, false
Documentation generated on Mon, 11 Mar 2019 13:52:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|