Featured On ...

asp.net

totalasp.co.uk

fuzzysoftware.com

devdex.com

123aspx.com

dotnetfreaks.com

411asp.net

and more ...

ASP.NET Validation Package Demo 7 - Most validators

The following page demonstrates most of the validators available with the ASP.NET Validation Package. This page contains a number of features that were first introduced in the 1.3 release of the validation package. Included in the release are inline message functions, which allow developers to embed properties into the message text. Click on 'show me the code' to take a sneak peek at how this works.

>> Show me the code!

>> Turn off client side validation!




ValidatorEntryDate

When the ValidatorEntryDate class is used to validate a field, the value entered must be a valid date whose format is either unambiguous or in a defined ambiguous format such as 02/02/02. The types of ambiguous formats accepted can be found in the ValidatorEntryDate class documentation.

This example accepts any unambiguous format or YYYY/MM/DD.

ValidatorEntryDateComparer

When the ValidatorEntryDateComparer class is used to validate a pair of fields, the validator makes a comparison of the two fields using the ComparisonMethod defined in the constructor. The ComparisonMethod values available are: equal to, not equal to, less than, less than equal to, greater than and greater than equal to. The the value entered in both fields must be a valid date whose format is either unambiguous or in a defined ambiguous format such as 02/02/02. The types of ambiguous formats accepted can be found in the ValidatorEntryDate class documentation.

This example accepts any unambiguous format or YYYY/MM/DD in both fields. The second date must be at least 4 days and 3 hours greater than the first date.

ValidatorEntryDateComparer

When the ValidatorEntryDateComparer class is used to validate a field against a literal date, the validation behaves much like the ValidatorEntryDateRange class. The value entered must be a valid date whose format is either unambiguous or in a defined ambiguous format such as 02/02/02. The types of ambiguous formats accepted can be found in the ValidatorEntryDate class documentation.

This example accepts any unambiguous format or YYYY/MM/DD and the date must be at least 4 days and 3 hours greater or equal to 1 Jan 2004 00:00:00.

ValidatorEntryDateRange

The ValidatorEntryDateRange class is used to validate a field against a date range. The date entered must lie between the two dates passed to the constructor of the class. The value entered must be a valid date whose format is either unambiguous or in a defined ambiguous format such as 02/02/02. The types of ambiguous formats accepted can be found in the ValidatorEntryDate class documentation.

This example accepts any unambiguous format or YYYY/MM/DD and the date must be greater or equal to 19 July 1967 00:00:00 and less than or equal to 28 August 2008 08:24:09.

ValidatorEntryDomain

The ValidatorEntryDomain class is used to validate a field in which a domain name must be entered.

ValidatorEntryEmail

The ValidatorEntryEmail class is used to validate a field in which an email address must be entered.

ValidatorEntryFloat

The ValidatorEntryFloat class is used to validate a field in which a floating point number must be entered. This type of validator can also be used to validate monetry amounts.

ValidatorEntryFloatRange

The ValidatorEntryFloatRange class is used to validate a field in which a floating point number must be entered that must lie between two numbers that are passed into the constructor of this class. In this example, the number must lie between 1000.01 and 10000.92.

ValidatorEntryInt

The ValidatorEntryInt class is used to validate a field in which an integer must be entered.

ValidatorEntryIntRange

The ValidatorEntryIntRange class is used to validate a field in which an integer must be entered that must lie between two numbers that are passed into the constructor of this class. In this example, the number must lie between 1000 and 10000.

ValidatorEntryNumericComparer

When the ValidatorEntryNumericComparer class is used to validate a pair of fields, the validator makes a comparison of the two fields using the ComparisonMethod defined in the constructor. The ComparisonMethod values available are: equal to, not equal to, less than, less than equal to, greater than and greater than equal to. The value entered in both fields must be a valid number (either a floating point number or an integer).

In this example the second field must be greater than the first field by 10.

ValidatorEntryNumericComparer

When the ValidatorEntryNumericComparer class is used to validate a field against a literal numeric value, the validator behaves much like the ValidatorEntryFloatRange class. The value entered in both fields must be a valid number (either a floating point number or an integer).

In this example the following field must be greater than 10.

ValidatorEntryRegex

The ValidatorEntryRegex class is used to validate a field against a regular expression. In this example, the field is being validated against the following regular expression: /^[0-9a-fA-F]{4}(-[0-9a-fA-F]{4}){3}$/, e.g. 42AC-F98F-9831-AA98.

ValidatorEntryRequired

The ValidatorEntryRequired class is used to validate a field against being empty.

ValidatorEntryTextComparer

When the ValidatorEntryTextComparer class is used to validate a pair of fields, the validator makes a comparison of the two fields using the ComparisonMethod defined in the constructor. The ComparisonMethod values available for text comparisons are: equal to and not equal to.

In this example both fields are password fields and the value of both must be identical to pass validation.

ValidatorEntryTextComparer

The ValidatorEntryTextComparer class can also be used to validate a field against a literal string. The CompareMethods available for text comparisons are: equal to and not equal to.

In this example the value of the field must not be 'zaphod'.

ValidatorEntryTextLength

The ValidatorEntryTextLength class is used to validate the length of the text in a field. Minimum and maximum values can be passed into the constructor to limit the length of the text to a certain range. In this example the text must be between 10 and 15 characters long.

ValidatorEntryUrl

The ValidatorEntryUrl class is used to validate a field in which a URL must be entered. URLs must contain either http, https or ftp as the protocol.

ValidatorEntryWordCount

The ValidatorEntryWordCount class is used to validate a field in which a certain number of words (as determined by the \w regular expression sequence). This class uses the ComparisonMethod enum to define how the comparison is made and so the number of words can be equal to, not equal to, less than, less than equal to, greater than or greater than equal to a certain number.

In this example exactly 4 words must be entered.

© 2002 - 2008 Copyright, Disclaimer and Privacy Statement