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 類別所定義。