Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ValidatePatternAttribute Constructor (String)

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Creates a new instance of the ValidatePatternAttribute class with a regular expression for validating the cmdlet parameter argument.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

public ValidatePatternAttribute(
	string regexPattern
)

Parameters

regexPattern
Type: System.String

A regular expression that defines the attribute pattern.

Exception Condition
ArgumentException

The regexPattern parameter has an argument that is not valid.

The ValidatePattern attribute uses a .NET Framework regular expression. For more information about regular expressions, see .NET Framework Regular Expressions.

For more information about the syntax and parameters that are used when declaring this attribute within a cmdlet, see ValidatePattern Attribute Declaration.

The following code example specifies a pattern of four digits, with each digit having the value of 0-9.

[ValidatePattern("[0-9][0-9][0-9][0-9]")]
[Parameter(Position=0,Mandatory = true)]
public int InputData
{
   get { return inputData; }
   set { inputData = value; }
}

private int inputData;

Return to top

Community Additions

Show: