summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TValueTypeValidator.php
diff options
context:
space:
mode:
authorwei <>2006-01-30 22:31:58 +0000
committerwei <>2006-01-30 22:31:58 +0000
commit265b7e85766ba403ca0a8b58648dd091e483cf38 (patch)
tree8303f80dd10a13ca7159e306ca97c31b00e0c4db /framework/Web/UI/WebControls/TValueTypeValidator.php
parent083f77f4ed265dc74b0530fa6f232248dbaacb41 (diff)
Adding THtmlArea.
Diffstat (limited to 'framework/Web/UI/WebControls/TValueTypeValidator.php')
-rw-r--r--framework/Web/UI/WebControls/TValueTypeValidator.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/framework/Web/UI/WebControls/TValueTypeValidator.php b/framework/Web/UI/WebControls/TValueTypeValidator.php
new file mode 100644
index 00000000..d24fda4f
--- /dev/null
+++ b/framework/Web/UI/WebControls/TValueTypeValidator.php
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * TRequiredValueTypeValidator class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TValueTypeValidator
+{
+ /**
+ * @return string the data type that the values being compared are converted to before the comparison is made. Defaults to String.
+ */
+ public function getValueType()
+ {
+ return $this->getViewState('ValueType','String');
+ }
+
+ /**
+ * Sets the data type (Integer, Double, Currency, Date, String) that the values being compared are converted to before the comparison is made.
+ * @param string the data type
+ */
+ public function setValueType($value)
+ {
+ $this->setViewState('ValueType',TPropertyValue::ensureEnum($value,'Integer','Double','Date','Currency','String'),'String');
+ }
+
+ /**
+ * Sets the date format for a date validation
+ * @param string the date format value
+ */
+ public function setDateFormat($value)
+ {
+ $this->setViewState('DateFormat', $value, '');
+ }
+
+ /**
+ * @return string the date validation date format if any
+ */
+ public function getDateFormat()
+ {
+ return $this->getViewState('DateFormat', '');
+ }
+
+
+ /**
+ * Determine if the given value is of a particular type using RegExp.
+ * @param string value to check
+ * @return boolean true if value fits the type expression.
+ */
+ protected function evaluateDataTypeCheck($value)
+ {
+ switch($this->getValueType())
+ {
+ case 'Integer':
+ return preg_match('/^[-+]?[0-9]+$/',trim($value));
+ case 'Float':
+ case 'Double':
+ return preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
+ case 'Currency':
+ return preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
+ case 'Date':
+ $dateFormat = $this->getDateFormat();
+ if(strlen($dateFormat))
+ return pradoParseDate($value, $dateFormat) !== null;
+ else
+ return strtotime($value) > 0;
+ }
+ return true;
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input data is of valid type.
+ * The validation always succeeds if ControlToValidate is not specified
+ * or the input data is empty.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
+ return true;
+
+ return $this->evaluateDataTypeCheck($value);
+ }
+}
+
+?> \ No newline at end of file