You can be very specific with regular expressions. Although I use regular expressions, they still look like an alien language to me. However, assuming that the 9 character requirement is 5 alpha characters and 4 numeric characters, you could do something like this:
Just my two cents with a slight adjustment to Rob’s suggestion. Since the requirement it not more than 9 characters, but no requirement for less than 9 characters, the repeat needs to be an at least with an upper bound. I added a few more samples, and changed the repeat to {0,5} which is at least 0 times and at most 5 times. I also changed the pattern to \w which is equivalent to [a-zA-Z_0-9], but you could change it to [a-zA-Z0-9]if you consider _ a special character.
You don’t need to validate or use the error provider if the mask is set as you can only enter the allowed characters. edit: You might use the errorprovider to indicate a computername already in use.
#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-forums_psf {
#----------------------------------------------
#region Import the Assemblies
#----------------------------------------------
[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
#----------------------------------------------
#region Generated Form Objects
#----------------------------------------------
[System.Windows.Forms.Application]::EnableVisualStyles()
$form1 = New-Object 'System.Windows.Forms.Form'
$maskedtextbox1 = New-Object 'System.Windows.Forms.MaskedTextBox'
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
#endregion Generated Form Objects
#----------------------------------------------
# User Generated Script
#----------------------------------------------
$form1_Load={
}
# --End User Generated Script--
#----------------------------------------------
#region Generated Events
#----------------------------------------------
$Form_StateCorrection_Load=
{
#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
$Form_Cleanup_FormClosed=
{
#Remove all event handlers from the controls
try
{
$form1.remove_Load($form1_Load)
$form1.remove_Load($Form_StateCorrection_Load)
$form1.remove_FormClosed($Form_Cleanup_FormClosed)
}
catch [Exception]
{ }
}
#endregion Generated Events
#----------------------------------------------
#region Generated Form Code
#----------------------------------------------
$form1.SuspendLayout()
#
# form1
#
$form1.Controls.Add($maskedtextbox1)
$form1.ClientSize = '213, 117'
$form1.Name = 'form1'
$form1.Text = 'Form'
$form1.add_Load($form1_Load)
#
# maskedtextbox1
#
$maskedtextbox1.Font = 'Microsoft Sans Serif, 12pt'
$maskedtextbox1.Location = '24, 34'
$maskedtextbox1.Mask = 'L-LL-0000'
$maskedtextbox1.Name = 'maskedtextbox1'
$maskedtextbox1.Size = '128, 26'
$maskedtextbox1.TabIndex = 2
$form1.ResumeLayout()
#endregion Generated Form Code
#----------------------------------------------
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($Form_StateCorrection_Load)
#Clean up the control events
$form1.add_FormClosed($Form_Cleanup_FormClosed)
#Show the Form
return $form1.ShowDialog()
} #End Function
#Call the form
Call-forums_psf | Out-Null