Hello,
I would like to achieve a regular expression that matches the following criteria in a textbox.
First character needs to be a letter.
Second characters need to be two numbers.
Last characters need to be four letters.
For an example like this: A21ABCD, or G16YUZG etc.
Anyone who knows how to achieve this and I'd be very happy to have this solved.
Here is the code I have:
function Set-OSDComputerName {
$ErrorProvider.Clear()
if ($TBComputerName.Text.Length -eq 0) {
$ErrorProvider.SetError($GBComputerName, "Please enter a computer name")
}
else {
if ($TBComputerName.Text.Length -gt 6) {
$ErrorProvider.SetError($GBComputerName, "Computer name cannot be more than 6 characters")
}
else {
if ($TBComputerName.Text -match "^[-_]|[^a-zA-Z0-9-_]") {
$ErrorProvider.SetError($GBComputerName, "Computer name cannot contain special characters")
}
else {
$OSDComputerName = $TBComputerName.Text.Replace("[","").Replace("]","").Replace(":","").Replace(";","").Replace("|","").Replace("=","").Replace("+","").Replace("*","").Replace("?","").Replace("<","").Replace(">","").Replace("/","").Replace("\","").Replace(",","")
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$TSEnv.Value("OSDComputerName") = "$($OSDComputerName)"
$Form.Close()
}
}
}
}
Thaaanks!

