Validate Input Using Regular Expressions

Function parameters can be validated using standard regular expressions. For example, the next template function accepts only valid Knowledge Base article numbers beginning with "KB" and a six- digit number:

function Get-KnowledgeBaseArticle {
param(
[ValidatePattern('^KB\d{6}$')]
[String]
$KB
)

"You entered Knowledgebase ID $KB"
}

Twitter This Tip! ReTweet this Tip!


Posted Aug 24 2010, 08:00 AM by ps1

Comments

forcefx2 wrote re: Validate Input Using Regular Expressions
on 09-17-2010 11:22 AM

I think they have extended this to a 7 char now.

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.