ValidateLengthAttribute Class
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
Defines an attribute that uses minimum and maximum limits to validate the number of characters in a cmdlet parameter argument (This attribute can also be used by Windows PowerShell functions.)
Namespace: System.Management.Automation
Assembly: System.Management.Automation (in System.Management.Automation)
System.Management.Automation Namespace
How to Validate Argument Length
How to Declare Input Validation Rules
Windows PowerShell SDK
Namespace: System.Management.Automation
Assembly: System.Management.Automation (in System.Management.Automation)
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field)] public sealed class ValidateLengthAttribute : ValidateEnumeratedArgumentsAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field) */ public final class ValidateLengthAttribute extends ValidateEnumeratedArgumentsAttribute
The following code example shows how this attribute can be declared.
[Cmdlet(VerbsDiagnostic.Test, "ArgumentLength")] public class TestArgumentLengthCommand : Cmdlet { [ValidateLength(0, 10)] [Parameter(Position = 0, Mandatory = true)] public string UserName { get { return userName; } set { userName = value; } } private string userName; // Override input processing method. protected override void ProcessRecord() { WriteObject("Hello " + userName); } }
There are no established scenarios for explicitly creating a ValidateLengthAttribute object from within a cmdlet. The ValidateLengthAttribute object is created and used indirectly when the ValidateLength attribute is declared.
This attribute is declared when implementing a cmdlet parameter. the syntax used to declare this attribute, see ValidateLengthAttribute Declaration.
For examples of declaring other validation attributes, see How to Declare Input Validation Rules.
System.Object
System.Attribute
System.Management.Automation.Internal.CmdletMetadataAttribute
System.Management.Automation.ValidateArgumentsAttribute
System.Management.Automation.ValidateEnumeratedArgumentsAttribute
System.Management.Automation.ValidateLengthAttribute
System.Attribute
System.Management.Automation.Internal.CmdletMetadataAttribute
System.Management.Automation.ValidateArgumentsAttribute
System.Management.Automation.ValidateEnumeratedArgumentsAttribute
System.Management.Automation.ValidateLengthAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Target Platforms
Windows Developer Preview, Windows Server Developer PreviewReference
ValidateLengthAttribute MembersSystem.Management.Automation Namespace
Other Resources
ValidateLength Attribute DeclarationHow to Validate Argument Length
How to Declare Input Validation Rules
Windows PowerShell SDK
Send comments about this topic to Microsoft.