Originally Posted by
PM from ironj32
Hi Mvidas,
A while back ago you helped me with formating some numbers and it's awesome. However I would like to change it a little. I want to remove the "-" and I would like it to need to have exactly 9 numbers. I know how to remove the "-" and set the maximum length to 9: txtTaxID.Text = Left(tStr, 9), but I am having trouble setting the Minimum to 9. I would really appreciate your help! Thanks.
[vba]
Private Sub txtTaxID_Change()
Dim RegEx As Object, tStr As String
Set RegEx = CreateObject("vbscript.regexp")
RegEx.Global = True
RegEx.Pattern = "\D"
tStr = RegEx.Replace(txtTaxID.Text, "")
txtTaxID.Text = Left(tStr, 2) & IIf(Len(tStr) > 2, "-" & Mid(tStr, 3, 7), "")
Set RegEx = Nothing
End Sub
[/vba]