Contains Characters Validator
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The latest Enterprise Library information can be found at the Enterprise Library site. |
Class Name: ContainsCharactersValidator
Attribute Name: ContainsCharactersValidatorAttribute
Configuration tool name: Contains Characters Validator
Description
This validator checks that an arbitrary string, such as a string entered by a user in a Web form, contains any or all of the characters that are specified by the CharacterSet property.
Properties
The following table lists the Contains Characters Validator properties
Contains Characters Validator Properties
Property |
Description |
---|---|
CharacterSet |
This property defines the set of characters whose inclusion in a string you want to validate. |
ContainsCharacters |
This property determines whether the validator checks for Any of the characters defined in CharacterSet or for All of the characters. The default is Any. |
Negated |
This is a Boolean property. If it is set to True, it changes the validator's behavior so that it will fail if the condition is met, rather than when it is not met. The default is False. |
Tag |
This property is a user-supplied string. Typically, it is used to sort or categorize validation results that are in a log. |
MessageTemplate |
This property is a user-supplied string. Typically, it describes the validation result and is intended for a log. |
MessageTemplateResourceName |
If you do not want to use the MessageTemplate property to specify a message, you can use another template by specifying it with the MessageTemplateResourceName value. If you include both a MessageTemplate value and a MessageTemeplateResourceName value, the MessageTemplate value takes precedence. |
MessageTemplateResourceTypeName |
If you specify a MessageTemplateResourceName value then you must specify a MessageTemplateResourceTypeName value, which is the type of the template you want to use. |
Message Template Tokens
If the message template contains tokens (for instance, "{0}"), the validator will replace these tokens with values when the ValidationResult is created. The tokens supported by the ContainsCharactorsValidator are as follows:
Token |
Meaning |
---|---|
{3} |
The list of characters configured for this validator instance. |
{4} |
The type of character search (Any or All) configured for this validator instance. |
Examples
The following examples show how to use the validator with attributes.
Attributes
The following code example uses attributes to ensure that the product code contains the character "f", the character "s" and the character "p".
public class Product
{
[ContainsCharactersValidator("fsp", ContainsCharacters.All)]
public string ProductCode
{
get
{
return _productCode;
}
}
// ...
}
'Usage
Public Class Product
<ContainsCharactersValidator("fsp", ContainsCharacters.All)> _
ReadOnly Property ProductCode(ByVal _productCode As String)
Get
Return _productCode
End Get
End Property
' ...
End Class
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The latest Enterprise Library information can be found at the Enterprise Library site. |