PowerShell for Windows Admins

Jun 8 2014   7:32AM GMT

Function parameter validation – other validation options

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Some other options you can use for validating your input include:

[ValidateCount(1,10)]

tests the number of values being passed to the parameter – must be within the range (including end points ) specified

[ValidateLength(1,10)]

test the number of characters in a parameter value – must be within the specified range
[ValidatePattern("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")] ## IP Address
[ValidatePattern("[A-Z]{2,8}[0-9][0-9]“)]

tests the input value against a regular expression – the value must match the pattern otherwise an error will be thrown

[ValidateRange(0,10)]

the value must be between the endpoints of the range specified

[ValidateSet("Low", "Average", "High")]

the value must be a member of the set of values specified

Using these, together with the ValidateScript and Validate  NotNullorEmpty options, provide you an easy way to test and validate your function inputs.  Much easier than writing your own code

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: