cvs: pear /HTML_OOH_Form/container form_container_usernumber.php

From: Date: Tue, 20 Nov 2001 01:08:37 +0000
Subject: cvs: pear /HTML_OOH_Form/container form_container_usernumber.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1375@lists.php.net to get a copy of this message
uw Mon Nov 19 20:08:37 2001 EDT Added files: /pear/HTML_OOH_Form/container form_container_usernumber.php Log: numbers Index: pear/HTML_OOH_Form/container/form_container_usernumber.php +++ pear/HTML_OOH_Form/container/form_container_usernumber.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // // $Id: form_container_usernumber.php,v 1.1 2001/11/20 01:08:37 uw Exp $ require_once('HTML_OOH_Form/container/form_container.php'); /** * Floating point numbers entered by humans * * Note: this one does not reformat (encode/decode) weird user input. * * @package HTML_OOH_Form * @version $Id: form_container_usernumber.php,v 1.1 2001/11/20 01:08:37 uw Exp $ */ class form_container_usernumber extends form_container { var $allowed_slots = array( 'value' => 'mixed', 'minlength' => 'string', 'maxlength' => 'string', 'length_e' => 'string', 'valid_regex' => 'string', 'valid_icase' => 'boolean', 'valid_e' => 'string', 'precision' => 'integer' ); /** * Maximum precision used when displaying the number */ var $precision = 8; // note this is compared with the unencoded value var $valid_regex = '[0-9]*[\.]*[0-9]*'; var $vaid_e = 'Please enter a number'; function decode($value) { $flag_neg = false; if (strcmp((float)$value, (string)$value) != 0) { $value = trim($value); if ('+' == $value{0}) { $value = substr($value, 1); } else if ('-' == $value{0}) { $value = substr($value, 1); $flag_neg = true; } $pos_dot = strpos($value, '.'); $pos_com = strpos($value, ','); if (false === $pos_dot && false === $pos_com) { // 123 $value = (float)$value; } else if (false === $pos_dot && $pos_com) { // 123,45[6...] $value = (float)str_replace(',', '.', $value); } else if ($pos_dot && false === $pos_com) { // 123.45[6...] if ($pos_dot == strlen($value) - 2) { // 123.45 $value = (float)$value; } else { // 123.456[7...] $value = (float)str_replace('.', '', $value); } } else if ($pos_dot && $pos_com) { if ($pos_dot < $pos_com) { // 123.456,78 $value = str_replace('.', '', $value); $value = (float)str_replace(',', '.', $value); } else { // 123,456.78 $value = (float)str_replace(',', '', $value); } } } if ($flag_neg) $value = -1 * $value; return $value; } // end func decode function encode($value) { return number_format($value, $this->precision, ',', '.'); } // end func encode /** * Returns the result of the (serverside) validation. * * @return string Error message if there is an error * @access public * @see validateLength(), validateRegEx(), doValidation() * @abstract */ function validate() { return $this->validateLength . $this->validateRegEx; } // end func validate } // end class form_container_userfloat ?>

« previous php.pear.cvs (#1375) next »