I am not having any luck trying to get my first function to work. I need to test three strings to see if the the string is empty, or if any non allowed characters are present. If there is a invalid string, set $Errorstate to 2. and amended a string with a new line of text. If no error is present exit the function. As It stands right now the code accepts all input and passes It through.
#Error Function
Function Test-isGood($Vaule,$Errtxt,$Msg,$State){
if($Vaule -eq ""){
$Msg = $Msg + "`n" + "Please Fill in the"+ "$Errtxt" + "Box"
$State = 2
}
if ($Vaule -match "\A[^a-z0-9 _&-]+\Z") {
$State = $State
}else{
$Msg = $Msg + "`n" + "Please Use A-Z, a-z and 0-9 in the"+"$Errtxt" +"Box"
$State = 2
}
$Errorstate = $state
$ErrorMessage = $Msg
}
#Name Holders
$Temp1 = "S0#"
$Temp2 = "Job Name"
$Temp3 = "Contractor"
#Call Error Function
Test-isGood $TextBox1.Text $Temp1 $ErrorMessage $Errorstate
Test-isGood $TextBox2.Text $Temp2 $ErrorMessage $Errorstate
Test-isGood $TextBox3.Text $Temp3 $ErrorMessage $Errorstate
Thanks for you help, gizmobrat