[pLog-svn] r4974 - in plog/branches/lifetype-1.2/class/data/validator: . rules

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Sat Mar 3 20:34:23 EST 2007


Author: jondaley
Date: 2007-03-03 20:34:23 -0500 (Sat, 03 Mar 2007)
New Revision: 4974

Added:
   plog/branches/lifetype-1.2/class/data/validator/floatvalidator.class.php
   plog/branches/lifetype-1.2/class/data/validator/rules/floatrule.class.php
Log:
new float validator

Added: plog/branches/lifetype-1.2/class/data/validator/floatvalidator.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/floatvalidator.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/data/validator/floatvalidator.class.php	2007-03-04 01:34:23 UTC (rev 4974)
@@ -0,0 +1,27 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/data/validator/validator.class.php" );
+
+    /**
+     * \ingroup Validator
+     *
+     * Checks that it is really a float value.
+     *
+     * @see IntRule
+     */
+    class FloatValidator extends Validator 
+    {
+		/**
+		 * Constructor.
+		 *
+		 * @param signed Whether to allow signed float or not.
+		 */
+    	function FloatValidator()
+        {
+        	$this->Validator();
+        	
+            lt_include( PLOG_CLASS_PATH."class/data/validator/rules/floatrule.class.php" );
+            $this->addRule( new FloatRule());
+        }
+    }
+?>
\ No newline at end of file

Added: plog/branches/lifetype-1.2/class/data/validator/rules/floatrule.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/rules/floatrule.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/data/validator/rules/floatrule.class.php	2007-03-04 01:34:23 UTC (rev 4974)
@@ -0,0 +1,42 @@
+<?php
+
+    lt_include(PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php");
+
+    define( "FLOAT_RULE_REG_EXP", "^([+-]?[0-9][0-9.]*)|0$");
+    define( "ERROR_RULE_FLOAT_FORMAT_WRONG", "error_rule_float_format_wrong");
+
+    /**
+	 * \ingroup Validator_Rules
+	 *
+	 * Checks if the given value is an integer, not only in type but also in format.
+	 * It will return ERROR_RULE_INT_FORMAT_WRONG if the format is not correct
+     */
+    class FloatRule extends RegExpRule
+    {
+        /**
+         * Initialize the rule
+         */
+        function FloatRule()
+        {
+            $this->RegExpRule(FLOAT_RULE_REG_EXP, false);
+        }
+
+        /**
+		 * Returns true if the given value is an integer, or false otherwise. In case of error
+		 * it will also set the error code to ERROR_RULE_INT_FORMAT_WRONG
+         */
+        function validate($value)
+        {
+            if (parent::validate($value))
+            {
+                $this->_setError(false);
+                return true;
+            }
+            else
+            {
+                $this->_setError(ERROR_RULE_FLOATT_FORMAT_WRONG);
+                return false;
+            }
+        }
+    }
+?>
\ No newline at end of file



More information about the pLog-svn mailing list