|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZIntegerValidator class 00004 // 00005 // Created on: <08-Jul-2002 17:15:51 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezintegervalidator.php 00032 */ 00033 00034 /*! 00035 \class eZIntegerValidator ezintegervalidator.php 00036 \brief The class eZIntegerValidator does 00037 00038 */ 00039 00040 //include_once( "lib/ezutils/classes/ezregexpvalidator.php" ); 00041 00042 class eZIntegerValidator extends eZRegExpValidator 00043 { 00044 /*! 00045 Constructor 00046 */ 00047 function eZIntegerValidator( $min = false, $max = false ) 00048 { 00049 $rule = array( "accepted" => "/^-?[0-9]+$/", 00050 "intermediate" => "/(-?[0-9]+)/", 00051 "fixup" => "" ); 00052 $this->eZRegExpValidator( $rule ); 00053 $this->MinValue = $min; 00054 $this->MaxValue = $max; 00055 if ( $max !== false and $min !== false ) 00056 $this->MaxValue = max( $min, $max ); 00057 } 00058 00059 function setRange( $min, $max ) 00060 { 00061 $this->MinValue = $min; 00062 $this->MaxValue = $max; 00063 if ( $max !== false and $min !== false ) 00064 $this->MaxValue = max( $min, $max ); 00065 } 00066 00067 function validate( $text ) 00068 { 00069 $state = eZRegExpValidator::validate( $text ); 00070 if ( $state == eZInputValidator::STATE_ACCEPTED ) 00071 { 00072 if ( ( $this->MinValue !== false and $text < $this->MinValue ) or 00073 ( $this->MaxValue !== false and $text > $this->MaxValue ) ) 00074 $state = eZInputValidator::STATE_INTERMEDIATE; 00075 } 00076 return $state; 00077 } 00078 00079 function fixup( $text ) 00080 { 00081 if ( preg_match( $this->RegExpRule["intermediate"], $text, $regs ) ) 00082 $text = $regs[1]; 00083 if ( $this->MinValue !== false and $text < $this->MinValue ) 00084 $text = $this->MinValue; 00085 else if ( $this->MaxValue !== false and $text > $this->MaxValue ) 00086 $text = $this->MaxValue; 00087 return $text; 00088 } 00089 00090 /// \privatesection 00091 public $MinValue; 00092 public $MaxValue; 00093 } 00094 00095 ?>