00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( "lib/ezutils/classes/ezregexpvalidator.php" );
00041
00042 class eZIntegerValidator extends eZRegExpValidator
00043 {
00044
00045
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 == EZ_INPUT_VALIDATOR_STATE_ACCEPTED )
00071 {
00072 if ( ( $this->MinValue !== false and $text < $this->MinValue ) or
00073 ( $this->MaxValue !== false and $text > $this->MaxValue ) )
00074 $state = EZ_INPUT_VALIDATOR_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
00091 var $MinValue;
00092 var $MaxValue;
00093 }
00094
00095 ?>