In past posts, some of the functions have included param / parameter to test or set various variables. This is a very good (and likely just a very correct) way of scripting, you should learn to do it. I should learn to do it more too but I’m too concerned about making user input correct AND easy for the user to deal with AND as flexible as possible. I do not want to be making multiple functions to make sure input data is correct.
So I made this simple function
function FNvalid_entry($msg,$regX){
while (!$val_ent){
$val_ent = read-host $msg
if ([regex]::ismatch($val_ent,$regX)){
break
}else{
write-host -fore yellow "Bad format"
remove-variable val_ent
}
}
return $val_ent
}
Continue reading “Error, does not compute – Input validation”