From 8569373e8cb6163f182fe13ffbc44ea1b2c961cd Mon Sep 17 00:00:00 2001
From: xue <>
Date: Thu, 23 Feb 2006 03:38:15 +0000
Subject: more clean up work about validators.
---
.../Controls/Samples/TCompareValidator/Home.page | 34 +++-
.../Controls/Samples/TDataTypeValidator/Home.page | 57 +++++++
.../Controls/Samples/TDataTypeValidator/Home.php | 8 +
.../protected/pages/Controls/Validation.page | 178 ++++++++-------------
4 files changed, 164 insertions(+), 113 deletions(-)
create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.page
create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php
(limited to 'demos/quickstart/protected/pages/Controls')
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page
index ab99436a..c5cec8af 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page
@@ -1,7 +1,7 @@
Note:TCompareValidator will start
+ Note: TCompareValidator will start
to validate only if both inputs are not empty. Note: TDataTypeValidator will start
+to validate only if both inputs are not empty.TCompareValidator Samples
-
@@ -39,6 +39,38 @@ Compare validator with client-side validation disabled:
+
+
+
+
+Comparing with a constant value:
+
+
+
+
+
+
+Comparing with an integer:
+
+
+
+TDataTypeValidator Samples
+
+
+
+
+
+
+
+
+Data type validator with default settings:
+
+
+
+
+
+
+
+Data type validator with client-side validation disabled:
+
+
+
+
+
+
+
+Validating a date input:
+
+
+
+
Validation is performed when a postback control, such as a TButton, a TLinkButton or a TTextBox (under AutoPostBack mode) is submitting the page and its CausesValidation property is true.
- -Validator controls always validate the associated input control on the serve side. -In addition, if EnableClientScript is true, validation will also be performed on the client-side using javascript. Client-side validation will validate user input before it is sent to the server. The form data will not be submitted if any error is detected. This avoids the round-trip of information necessary for server-side validation.
- -Every validator component has the following properties, defined in the TBaseValidator class. - -
+Validation controls, called validators, perform validation on user-entered data values when they are post back to the server. The validation is triggered by a postback control, such as a TButton, a TLinkButton or a TTextBox (under AutoPostBack mode) whose CausesValidation property is true. +
-+Validation is always performed on server side. If EnableClientScript is true and the client browser supports JavaScript, validators may also perform client-side validation. Client-side validation will validate user input before it is sent to the server. The form data will not be submitted if any error is detected. This avoids the round-trip of information necessary for server-side validation. +
++Validators share a common set of properties, which are defined in the base class TBaseValidator class and listed as follows, +
+-This is the simplest validator, ensuring that the input field has some sort of value. To ensure that all of our input fields are required, add a TRequiredFieldValidator component for each of the input fields. The TRequiredFieldValidator also has the following property. +TRequiredFieldValidator ensures that the user enters some data in the specified input field. By default, TRequiredFieldValidator will check if the user input is empty or not. The validation fails if the input is empty. By setting InitialValue, the validator can check if the user input is different from InitialValue. If not, the validation fails.
-The TRegularExpressionValidator has the following property in addition to the parent TBaseValidator properties. -
-[\w]{6,}
(0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
\d{3}(-(\d{4}|\d{2}))?
(\(\d{3}\)|\d{3}-)?\d{8}
\d{6}
\d{18}|\d{15}
((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
\d{5}(-\d{4})?
\d{3}-\d{2}-\d{4}
-Note, if the value being validated is empty, TRegularExpressionValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty. +
+TRegularExpressionValidator verifies the user input against a regular pattern. The validation fails if the input does not match the pattern. The regular expression can be specified by the RegularExpression property. Some commonly used regular expressions include: +
+[\w]{6,}
(0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
\d{3}(-(\d{4}|\d{2}))?
(\(\d{3}\)|\d{3}-)?\d{8}
\d{6}
\d{18}|\d{15}
((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
\d{5}(-\d{4})?
\d{3}-\d{2}-\d{4}
+More regular expression patterns can be found on the Internet, e.g. +http://regexlib.com/. +
++Note, TRegularExpressionValidator only checks for nonempty user input. Use a TRequiredFieldValidator to ensure the user input is not empty.
-TEmailAddressValidator validates whether the value of an associated input component is a valid email address. If CheckMXRecord is true, besides checking the format of the input value, the validator will also check MX record for the email address, provided checkdnsrr() is available in the installed PHP. +
+TEmailAddressValidator verifies that the user input is a valid email address. The validator uses a regular expression to check if the input is in a valid email address format. If CheckMXRecord is true, the validator will also check whether the MX record indicated by the email address is valid, provided checkdnsrr() is available in the installed PHP.
-Note, if the value being validated is empty, TEmailAddressValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty. +Note, if the input being validated is empty, TEmailAddressValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty.
The validator TCompareValidator is used to compare two input fields, the comparison can be made in many ways. The following are the properties of the TCompareValidator in addition to the parent TBaseValidator. -
-To specify the input component to validate, set the ControlToValidate property to the ID of the input component. To compare the associated input component with another input component, set the ControlToCompare property to the ID of the component to compare with.
- -To compare the associated input component with a constant value, specify the constant value to compare with by setting the ValueToCompare property.
- -The ValueType property is used to specify the data type 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.
-Use the Operator property to specify the type of comparison to perform. If you set the Operator property to DataTypeCheck, the TCompareValidator component will ignore the ControlToCompare and ValueToCompare properties and simply indicates whether the value entered into the input component can be converted to the data type specified by the ValueType property.
- -Note that if the input control is empty, no validation functions are called and validation succeeds. Use a RequiredFieldValidator control to require the user to enter data into the input control.
--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: +TCompareValidator compares the user input with a constant value specified by ValueToCompare, or another user input specified by ControlToCompare. The Operator property specifies how to compare the values, which includes Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan and LessThanEqual. Before comparison, the values being compared will be converted to the type specified by DataType listed as follows,
+Note, if the input being validated is empty, TEmailAddressValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty. +
++TDataTypeValidator verifies if the input data is of specific type indicated by DataType. The data types that can be checked against are the same as those in TCompareValidator.
+TRangeValidator verifies 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 DataType 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 data types that can be checked against are the same as those in TCompareValidator. +
+TCustomValidator performs user-defined validation (either server-side or client-side or both) on an input control. @@ -174,6 +121,13 @@ function ValidationFunctionName(sender, parameter)
+TValidationSummary displays a summary of validation errors inline on a Web page, in a message box, or both. +
++By default, a validation summary will collect ErrorMessage of all failed validators on the page. If ValidationGroup is not empty, only those validators who belong to the group will show their error messages in the summary. +
++The summary can be displayed as a list, a bulleted list, or a single paragraph based on the DisplayMode property. The messages shown can be prefixed with HeaderText. The summary can be displayed on the Web page or in a JavaScript message box, by setting the ShowSummary and ShowMessageBox properties, respectively. Note, the latter is only effective when EnableClientScript is true.