ezfloatvalidator.php

Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZFloatValidator class
00004 //
00005 //
00006 // Copyright (C) 1999-2003 Exponential. All rights reserved.
00007 //
00008 // This source file is part of the Exponential (tm) Open Source Content
00009 // Management System.
00010 //
00011 // This file may be distributed and/or modified under the terms of the
00012 // "GNU General Public License" version 2 as published by the Free
00013 // Software Foundation and appearing in the file LICENSE.GPL included in
00014 // the packaging of this file.
00015 //
00016 // Licencees holding valid "Exponential professional licences" may use this
00017 // file in accordance with the "Exponential professional licence" Agreement
00018 // provided with the Software.
00019 //
00020 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
00021 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00022 // PURPOSE.
00023 //
00024 // The "Exponential professional licence" is available at
00025 // http://ez.no/products/licences/professional/. For pricing of this licence
00026 // please contact us via e-mail to licence@ez.no. Further contact
00027 // information is available at http://ez.no/home/contact/.
00028 //
00029 // The "GNU General Public License" (GPL) is available at
00030 // http://www.gnu.org/copyleft/gpl.html.
00031 //
00032 // Contact licence@ez.no if any conditions of this licencing isn't clear to
00033 // you.
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 ?>
 

Exponential