~fusonic/chive/1.1

« back to all changes in this revision

Viewing changes to yii/validators/CNumberValidator.php

  • Committer: Matthias Burtscher
  • Date: 2010-02-12 09:12:35 UTC
  • Revision ID: matthias.burtscher@fusonic.net-20100212091235-jqxrb62klx872ajc
* Updated Yii to 1.1.0
* Removed CodePress and CodeMirror
* Updated jQuery and some plugins
* Cleaned some code ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
6
 * @link http://www.yiiframework.com/
7
 
 * @copyright Copyright &copy; 2008-2009 Yii Software LLC
 
7
 * @copyright Copyright &copy; 2008-2010 Yii Software LLC
8
8
 * @license http://www.yiiframework.com/license/
9
9
 */
10
10
 
12
12
 * CNumberValidator validates that the attribute value is a number.
13
13
 *
14
14
 * @author Qiang Xue <qiang.xue@gmail.com>
15
 
 * @version $Id: CNumberValidator.php 1178 2009-06-26 20:13:31Z qiang.xue $
 
15
 * @version $Id: CNumberValidator.php 1678 2010-01-07 21:02:00Z qiang.xue $
16
16
 * @package system.validators
17
17
 * @since 1.0
18
18
 */
54
54
        protected function validateAttribute($object,$attribute)
55
55
        {
56
56
                $value=$object->$attribute;
57
 
                if($this->allowEmpty && ($value===null || $value===''))
 
57
                if($this->allowEmpty && $this->isEmpty($value))
58
58
                        return;
59
59
                if($this->integerOnly)
60
60
                {
61
 
                        if(is_string($value) && !preg_match('/^\s*[+-]?\d+\s*$/',$value))
 
61
                        if(!preg_match('/^\s*[+-]?\d+\s*$/',"$value"))
62
62
                        {
63
63
                                $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be an integer.');
64
64
                                $this->addError($object,$attribute,$message);
66
66
                }
67
67
                else
68
68
                {
69
 
                        if(is_string($value) && !preg_match('/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/',$value))
 
69
                        if(!preg_match('/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/',"$value"))
70
70
                        {
71
71
                                $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be a number.');
72
72
                                $this->addError($object,$attribute,$message);