[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZFloatValidator class 4 // 5 // 6 // SOFTWARE NAME: eZ publish 7 // SOFTWARE RELEASE: 3.9.0 8 // BUILD VERSION: 17785 9 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 10 // SOFTWARE LICENSE: GNU General Public License v2.0 11 // NOTICE: > 12 // This program is free software; you can redistribute it and/or 13 // modify it under the terms of version 2.0 of the GNU General 14 // Public License as published by the Free Software Foundation. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of version 2.0 of the GNU General 22 // Public License along with this program; if not, write to the Free 23 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 // MA 02110-1301, USA. 25 // 26 // 27 28 /*! \file ezfloatvalidator.php 29 */ 30 31 /*! 32 \class eZFloatValidator ezintegervalidator.php 33 \brief The class eZFloatValidator does 34 35 */ 36 37 include_once ( "lib/ezutils/classes/ezregexpvalidator.php" ); 38 39 class eZFloatValidator extends eZRegExpValidator 40 { 41 /*! 42 Constructor 43 */ 44 function eZFloatValidator( $min = false, $max = false ) 45 { 46 $rule = array( "accepted" => "/^-?[0-9]+([.][0-9]+)?$/", 47 "intermediate" => "/(-?[0-9]+([.][0-9]+)?)/", 48 "fixup" => "" ); 49 $this->eZRegExpValidator( $rule ); 50 $this->MinValue = $min; 51 $this->MaxValue = $max; 52 if ( $max !== false and $min !== false ) 53 $this->MaxValue = max( $min, $max ); 54 } 55 56 function setRange( $min, $max ) 57 { 58 $this->MinValue = $min; 59 $this->MaxValue = $max; 60 if ( $max !== false and $min !== false ) 61 $this->MaxValue = max( $min, $max ); 62 } 63 64 function validate( $text ) 65 { 66 $state = eZRegExpValidator::validate( $text ); 67 if ( $state == EZ_INPUT_VALIDATOR_STATE_ACCEPTED ) 68 { 69 if ( ( $this->MinValue !== false and $text < $this->MinValue ) or 70 ( $this->MaxValue !== false and $text > $this->MaxValue ) ) 71 $state = EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE; 72 } 73 return $state; 74 } 75 76 function &fixup( $text ) 77 { 78 if ( preg_match( $this->RegExpRule["intermediate"], $text, $regs ) ) 79 $text = $regs[1]; 80 if ( $this->MinValue !== false and $text < $this->MinValue ) 81 $text = $this->MinValue; 82 else if ( $this->MaxValue !== false and $text > $this->MaxValue ) 83 $text = $this->MaxValue; 84 return $text; 85 } 86 87 /// \privatesection 88 var $MinValue; 89 var $MaxValue; 90 } 91 92 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |