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