Export (0) Print
Expand All

RegexStringValidatorAttribute Constructor

Initializes a new instance of the RegexStringValidatorAttribute object.

Namespace:  System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)

public RegexStringValidatorAttribute(
	string regex
)

Parameters

regex
Type: System.String

The string to use for regular expression validation.

The regex parameter contains the regular expression pattern that a string must match before it can be assigned to the decorated configuration-element property.

You use this constructor in the attributed model to ensure that the string value assigned to the related property contains only the allowed characters.

The following example shows how to use the RegexStringValidatorAttribute constructor.

[ConfigurationProperty("alias2", DefaultValue = "alias.txt",
    IsRequired = true, IsKey = false)]
[RegexStringValidator(@"\w+\S*")]
public string Alias2
{
    get
    {
        return (string)this["alias2"];
    }
    set
    {
        this["alias2"] = value;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft