RegexStringValidatorAttribute.ValidatorInstance Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets an instance of the RegexStringValidator class.
public:
virtual property System::Configuration::ConfigurationValidatorBase ^ ValidatorInstance { System::Configuration::ConfigurationValidatorBase ^ get(); };
public override System.Configuration.ConfigurationValidatorBase ValidatorInstance { get; }
member this.ValidatorInstance : System.Configuration.ConfigurationValidatorBase
Public Overrides ReadOnly Property ValidatorInstance As ConfigurationValidatorBase
Property Value
The ConfigurationValidatorBase validator instance.
Examples
The following example shows how to use the ValidatorInstance method.
ConfigurationValidatorBase valBase;
RegexStringValidatorAttribute rstrValAttr =
new RegexStringValidatorAttribute(@"\w+\S*");
// Get the regular expression string.
string regex = rstrValAttr.Regex;
Console.WriteLine("Regular expression: {0}", regex);
string badValue = "&%$bbb";
string goodValue = "filename.txt";
try
{
valBase = rstrValAttr.ValidatorInstance;
valBase.Validate(goodValue);
// valBase.Validate(badValue);
}
catch (ArgumentException e)
{
// Display error message.
string msg = e.ToString();
#if DEBUG
Console.WriteLine(msg);
#endif
}
Dim valBase As _
ConfigurationValidatorBase
Dim rstrValAttr As _
New RegexStringValidatorAttribute("\w+\S*")
' Get the regular expression string.
Dim regex As String = _
rstrValAttr.Regex
Console.WriteLine( _
"Regular expression: {0}", regex)
Dim badValue As _
String = "&%$bbb"
Dim goodValue As _
String = "filename.txt"
Try
valBase = rstrValAttr.ValidatorInstance
valBase.Validate(goodValue)
' valBase.Validate(badValue);
Catch e As ArgumentException
' Display error message.
Dim msg As String = e.ToString()
#If DEBUG Then
Console.WriteLine(msg)
#End If
End Try '
Remarks
You use the ValidatorInstance property to perform string validation by calling its Validate method.
Applies to
See also
Colaborar con nosotros en GitHub
El origen de este contenido se puede encontrar en GitHub, donde también puede crear y revisar problemas y solicitudes de incorporación de cambios. Para más información, consulte nuestra guía para colaboradores.