ValidateLength 属性声明
ValidateLength 属性指定 cmdlet 参数参数的最小和最大字符数。 Windows PowerShell 函数也可以使用此属性。
语法
[ValidateLength(int minLength, int maxlength)]
参数
MinLength
(System.Int32) 必需。 指定允许的最小字符数。
MaxLength
(System.Int32) 必需。 指定允许的最大字符数。
注解
有关如何声明此属性的详细信息,请参阅 如何声明输入验证规则。
如果未使用此属性,则相应的参数参数可以是任何长度。
Windows PowerShell 运行时在以下情况下引发错误:
当
MaxLength
属性参数的值小于MinLength
属性参数的值时。当
MaxLength
属性参数设置为 0 时。当参数不是字符串时。
ValidateLength 属性由 System.Management.Automation.ValidateLengthAttribute 类定义。