Trying to validate that a date entered is correct using powershell. So far this is what I have:
function ValidateDate
{
param([string]$date=$_)
$result = 0
[bool]$valid = $false
if (!([DateTime]::TryParse($date, [ref]$result))){
Write-Host "Your date $date was invalid. Please try again."
$date = Read-Host "Please enter the date with the following format mm/dd/yy: "
ValidateDate $date
}
else{$valid = $true}
Return $valid
}
When running the script, I enter a wrong date on purpose, it prompts me to revise the date, and then it should return a true value once the date is correct. Unfortunately this is the output I get:
PS C:\Users\bvandermark> ValidateDate 6/51/12
Your date 6/51/12 was invalid. Please try again.
True
False
Not sure why the false is there as well. Any thoughts?

New Topic/Question
Reply



MultiQuote



|