From d7c8a56d49200cb46d94403934674d670035ff20 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 22 Feb 2006 05:09:29 +0000 Subject: cleanup of validators. --- .gitattributes | 2 +- .../Controls/Samples/LabeledTextBox1/Home.php | 2 +- .../protected/pages/Controls/Validation.page | 33 ++++++- framework/Web/UI/WebControls/TCompareValidator.php | 7 +- framework/Web/UI/WebControls/TCustomValidator.php | 2 +- .../Web/UI/WebControls/TDataTypeValidator.php | 107 ++++++++++++++++++++ .../Web/UI/WebControls/TValueTypeValidator.php | 108 --------------------- 7 files changed, 144 insertions(+), 117 deletions(-) create mode 100644 framework/Web/UI/WebControls/TDataTypeValidator.php delete mode 100644 framework/Web/UI/WebControls/TValueTypeValidator.php diff --git a/.gitattributes b/.gitattributes index f59e7084..0d8b8ab2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -713,6 +713,7 @@ framework/Web/UI/WebControls/TDataGridColumn.php -text framework/Web/UI/WebControls/TDataList.php -text framework/Web/UI/WebControls/TDataSourceControl.php -text framework/Web/UI/WebControls/TDataSourceView.php -text +framework/Web/UI/WebControls/TDataTypeValidator.php -text framework/Web/UI/WebControls/TDatePicker.php -text framework/Web/UI/WebControls/TDropDownList.php -text framework/Web/UI/WebControls/TEditCommandColumn.php -text @@ -754,7 +755,6 @@ framework/Web/UI/WebControls/TTemplateColumn.php -text framework/Web/UI/WebControls/TTextBox.php -text framework/Web/UI/WebControls/TTextHighlighter.php -text framework/Web/UI/WebControls/TValidationSummary.php -text -framework/Web/UI/WebControls/TValueTypeValidator.php -text framework/Web/UI/WebControls/TWebControl.php -text framework/Web/UI/WebControls/TWebControlAdapter.php -text framework/Web/UI/WebControls/TWizard.php -text diff --git a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php index 2b18972d..2309bd88 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php @@ -1,6 +1,6 @@ TRangeValidator

+TRangeValidator tests whether an input value is within a specified range.

+

+TRangeValidator uses three key properties to perform its validation. The MinValue and MaxValue properties specify the minimum and maximum values of the valid range. The ValueType property specifies the data type of the value being validated. The value will be first converted into the specified type and then compare with the valid range. The following value types are supported: +

+ -

TValueTypeValidator

+

TDataTypeValidator

- +

TCustomValidator

+TCustomValidator performs user-defined validation (either server-side or client-side or both) on an input control. +

+

+To create a server-side validation function, provide a handler for the OnServerValidate event that performs the validation. The data string of the input control to validate can be accessed by the event parameter's Value property. The result of the validation should be stored in the IsValid property of the parameter. +

+

+To create a client-side validation function, add the client-side validation javascript function to the page template and assign its name to the ClientValidationFunction property. The function should have the following signature:

+ + + diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php index 9b8dabd5..6cc9d0e5 100644 --- a/framework/Web/UI/WebControls/TCompareValidator.php +++ b/framework/Web/UI/WebControls/TCompareValidator.php @@ -30,7 +30,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * of both comparison values. Both values are automatically converted to this data * type before the comparison operation is performed. The following value types are supported: * - Integer A 32-bit signed integer data type. - * - Double A double-precision floating point number data type. + * - Float A double-precision floating point number data type. * - Currency A decimal data type that can contain currency symbols. * - Date A date data type. The format follows the GNU date syntax. * - String A string data type. @@ -61,12 +61,12 @@ class TCompareValidator extends TBaseValidator } /** - * Sets the data type (Integer, Double, Currency, 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 setValueType($value) { - $this->setViewState('ValueType',TPropertyValue::ensureEnum($value,'Integer','Double','Date','Currency','String'),'String'); + $this->setViewState('ValueType',TPropertyValue::ensureEnum($value,'Integer','Float','Date','Currency','String'),'String'); } /** @@ -192,7 +192,6 @@ class TCompareValidator extends TBaseValidator case 'Integer': return array(intval($value1), intval($value2)); case 'Float': - case 'Double': return array(floatval($value1), floatval($value2)); case 'Currency': if(preg_match('/[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?/',$value1,$matches)) diff --git a/framework/Web/UI/WebControls/TCustomValidator.php b/framework/Web/UI/WebControls/TCustomValidator.php index e92ae828..b72ec344 100644 --- a/framework/Web/UI/WebControls/TCustomValidator.php +++ b/framework/Web/UI/WebControls/TCustomValidator.php @@ -116,7 +116,7 @@ class TCustomValidator extends TBaseValidator * TServerValidateEventParameter class * * TServerValidateEventParameter encapsulates the parameter data for - * ServerValidate event of TCustomValidator components. + * OnServerValidate event of TCustomValidator components. * * @author Qiang Xue * @version $Revision: $ $Date: $ diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php new file mode 100644 index 00000000..daaa9b6e --- /dev/null +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -0,0 +1,107 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * Using TBaseValidator class + */ +Prado::using('System.Web.UI.WebControls.TBaseValidator'); + +/** + * TDataTypeValidator class + * + * @author Wei Zhuo + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TDataTypeValidator extends TBaseValidator +{ + /** + * @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': + 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)) + { + $formatter = Prado::createComponent('System.Data.TSimpleDateFormatter',$dateFormat); + return $formatter->isValidDate($value); + } + 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 diff --git a/framework/Web/UI/WebControls/TValueTypeValidator.php b/framework/Web/UI/WebControls/TValueTypeValidator.php deleted file mode 100644 index 8b5d7bbc..00000000 --- a/framework/Web/UI/WebControls/TValueTypeValidator.php +++ /dev/null @@ -1,108 +0,0 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Revision: $ $Date: $ - * @package System.Web.UI.WebControls - */ - -/** - * Using TBaseValidator class - */ -Prado::using('System.Web.UI.WebControls.TBaseValidator'); - -/** - * TValueTypeValidator class - * - * @author Wei Zhuo - * @version $Revision: $ $Date: $ - * @package System.Web.UI.WebControls - * @since 3.0 - */ -class TValueTypeValidator extends TBaseValidator -{ - /** - * @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)) - { - $formatter = Prado::createComponent('System.Data.TSimpleDateFormatter',$dateFormat); - return $formatter->isValidDate($value); - } - 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 -- cgit v1.2.3