summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TRangeValidator.php
diff options
context:
space:
mode:
authorxue <>2006-04-25 01:27:04 +0000
committerxue <>2006-04-25 01:27:04 +0000
commit1afc913c386bba8e6072c278b0eb4fd9818ab310 (patch)
tree40cc63eb41f47e0ac392c692619640dca57cd262 /framework/Web/UI/WebControls/TRangeValidator.php
parentfd019bf034ef4dbedfc305c77fed0dbd83a732c4 (diff)
Undo previous checkin (which goes int 3.0 branch and will be merged back).
Diffstat (limited to 'framework/Web/UI/WebControls/TRangeValidator.php')
-rw-r--r--framework/Web/UI/WebControls/TRangeValidator.php41
1 files changed, 38 insertions, 3 deletions
diff --git a/framework/Web/UI/WebControls/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php
index b7387522..56cc16bc 100644
--- a/framework/Web/UI/WebControls/TRangeValidator.php
+++ b/framework/Web/UI/WebControls/TRangeValidator.php
@@ -29,6 +29,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
* operation is performed. The following value types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The date format can be specified by
* setting {@link setDateFormat DateFormat} property, which must be recognizable
* by {@link TSimpleDateFormatter}. If the property is not set,
@@ -86,13 +87,13 @@ class TRangeValidator extends TBaseValidator
}
/**
- * Sets the data type (Integer, Float, Date, String) that the values being
- * compared are converted to before the comparison is made.
+ * Sets the data type (Integer, Float, Currency, Date, String) that the values
+ * being compared are converted to before the comparison is made.
* @param string the data type
*/
public function setDataType($value)
{
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','String'),'String');
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String');
}
/**
@@ -130,6 +131,8 @@ class TRangeValidator extends TBaseValidator
return $this->isValidInteger($value);
case 'Float':
return $this->isValidFloat($value);
+ case 'Currency':
+ return $this->isValidCurrency($value);
case 'Date':
return $this->isValidDate($value);
default:
@@ -176,6 +179,38 @@ class TRangeValidator extends TBaseValidator
}
/**
+ * Determine if the value is a valid currency range,
+ * @param string currency value
+ * @return boolean true if within range.
+ */
+ protected function isValidCurrency($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
+ $valid=true;
+ $value = $this->getCurrencyValue($value);
+ if($minValue!=='')
+ $valid=$valid && ($value>= $this->getCurrencyValue($minValue));
+ if($maxValue!=='')
+ $valid=$valid && ($value<= $this->getCurrencyValue($minValue));
+ return $valid;
+ }
+
+ /**
+ * Parse the string into a currency value, return the float value of the currency.
+ * @param string currency as string
+ * @return float currency value.
+ */
+ protected function getCurrencyValue($value)
+ {
+ if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value,$matches))
+ return floatval($matches[0]);
+ else
+ return 0.0;
+ }
+
+ /**
* Determine if the date is within the specified range.
* Uses pradoParseDate and strtotime to get the date from string.
* @param string date as string to validate