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') 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 @@

TCompareValidator Samples

-

Note:TCompareValidator will start +

Note: TCompareValidator will start to validate only if both inputs are not empty.

@@ -39,6 +39,38 @@ Compare validator with client-side validation disabled: + + + + + + + + + +
+Comparing with a constant value: + + + + +
+Comparing with an integer: + + + + +
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.page new file mode 100644 index 00000000..783769ff --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.page @@ -0,0 +1,57 @@ + + +

TDataTypeValidator Samples

+

Note: TDataTypeValidator will start +to validate only if both inputs are not empty.

+ + + + + + + + + + + + + + + + + + +
+Data type validator with default settings: + + + + +
+Data type validator with client-side validation disabled: + + + + +
+Validating a date input: + + + + +
+ +
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php new file mode 100644 index 00000000..88d2dbf2 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page index 766925ca..6fe87fd0 100644 --- a/demos/quickstart/protected/pages/Controls/Validation.page +++ b/demos/quickstart/protected/pages/Controls/Validation.page @@ -2,137 +2,74 @@

Validation Controls

-

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. - -

-
ControlToValidate
-
The ID of the component for this validator. This property must be set to the ID path of an input component. The ID path is the dot-connected IDs of the components reaching from the validator's parent component to the target component.
- -
ErrorMessage
-
The text for the error message when the input component failed to validate.
- -
ValidationGroup
-
If the control causing the validation also sets its ValidationGroup property, only those validators having the same ValidationGroup value will do input validation. -
- -
Display
-
The display behavior of the error message in a validation component. The allowed values are: None, Static and Dynamic. The default is Static. - -
+

+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. +

-
EnableClientScript
-
Indicating whether client-side validation is enabled. Default 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, +

+

TRequiredFieldValidator

-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.

-
-
InitialValue
-
The associated input component fails validation if its value does not change from the InitialValue upon losing focus.
-
-

TRegularExpressionValidator

-

The TRegularExpressionValidator has the following property in addition to the parent TBaseValidator properties. -

-
-
RegularExpression
-
The regular expression that determines the pattern used to validate a field. Some commonly used regular expressions include: -
    -
  • At least 6 characters: [\w]{6,}
  • -
  • Japanese Phone Number: (0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
  • -
  • Japanese Postal Code: \d{3}(-(\d{4}|\d{2}))?
  • -
  • P.R.C. Phone Number: (\(\d{3}\)|\d{3}-)?\d{8}
  • -
  • P.R.C. Postal Code: \d{6}
  • -
  • P.R.C. Social Security Number: \d{18}|\d{15}
  • -
  • U.S. Phone Number: ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
  • -
  • U.S. ZIP Code: \d{5}(-\d{4})?
  • -
  • U.S. Social Security Number: \d{3}-\d{2}-\d{4}
  • -
- More regular expression patterns can be found on the Internet, e.g. - http://regexlib.com/. -
-
-

-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: +

+ +

+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

-

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.

TCompareValidator

-

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. -

-
-
ControlToCompare
-
The input component to compare with the input control being validated.
- -
ValueToCompare
-
A constant value to compare with the value entered by the user into the input component being validated.
- -
ValueType
-
The data type (Integer, Double, Currency, Date, String) that the values being compared are converted to before the comparison is made.
- -
Operator
-
The comparison operation to perform (Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, DataTypeCheck).
- -
DateFormat
-
The date format to use during comparision.
-
- -

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.

-
-
Integer
-
A 32-bit signed integer 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 date format depends on the DateFormat property.
- -
String
-
A string data type.
-
- -

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

-

-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,

  • String - A string data type.
  • @@ -141,13 +78,23 @@ TRangeValidator uses three key properties to perform its validation. The Min
  • Currency - A decimal data type that can contain currency symbols.
  • Date - A date data type. The date format can be specified by setting DateFormat property, which must be recognizable by TSimpleDateFormatter. If the property is not set, the GNU date syntax is assumed.
- +

+Note, if the input being validated is empty, TEmailAddressValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty. +

+

TDataTypeValidator

+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

+

+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

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

+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.

-- cgit v1.2.3