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 include_once( "lib/ezutils/classes/ezregexpvalidator.php" );
00040
00041 class eZFloatValidator extends eZRegExpValidator
00042 {
00043
00044
00045
00046 function eZFloatValidator( $min = false, $max = false )
00047 {
00048 $rule = array( "accepted" => "/^-?[0-9]+([.][0-9]+)?$/",
00049 "intermediate" => "/(-?[0-9]+([.][0-9]+)?)/",
00050 "fixup" => "" );
00051 $this->eZRegExpValidator( $rule );
00052 $this->MinValue = $min;
00053 $this->MaxValue = $max;
00054 if ( $max !== false and $min !== false )
00055 $this->MaxValue = max( $min, $max );
00056 }
00057
00058 function setRange( $min, $max )
00059 {
00060 $this->MinValue = $min;
00061 $this->MaxValue = $max;
00062 if ( $max !== false and $min !== false )
00063 $this->MaxValue = max( $min, $max );
00064 }
00065
00066 function validate( $text )
00067 {
00068 $state = eZRegExpValidator::validate( $text );
00069 if ( $state == EZ_INPUT_VALIDATOR_STATE_ACCEPTED )
00070 {
00071 if ( ( $this->MinValue !== false and $text < $this->MinValue ) or
00072 ( $this->MaxValue !== false and $text > $this->MaxValue ) )
00073 $state = EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE;
00074 }
00075 return $state;
00076 }
00077
00078 function &fixup( $text )
00079 {
00080 if ( preg_match( $this->RegExpRule["intermediate"], $text, $regs ) )
00081 $text = $regs[1];
00082 if ( $this->MinValue !== false and $text < $this->MinValue )
00083 $text = $this->MinValue;
00084 else if ( $this->MaxValue !== false and $text > $this->MaxValue )
00085 $text = $this->MaxValue;
00086 return $text;
00087 }
00088
00089
00090 var $MinValue;
00091 var $MaxValue;
00092 }
00093
00094 ?>