Validating Input

by Feb 8, 2011

You can also use regular expressions to validate user input. For example, the following piece of code only accepts three seven digit numbers:

do {
$result = Read-Host "3-7-digit number"
$result = $result.Trim("0")

} while ($result -notmatch '^\d{3,7}$')
"Entered: $result"

Twitter This Tip!
ReTweet this Tip!