hi, i am validating a postcode using this code, which puts the space in for the user, but what i really wanted to do was check each letter or use regex but i have never used regex before and i dont know how to check each letter.
the reason i need this is because the user can just enter 1234567 and it is validated fine, any ideas or good tutorials??
thanksCode:Private Sub TextBox9_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) TextBox9.Text = Trim(TextBox9.Text) Dim strPhone As String strPhone = Replace(TextBox9.Text, " ", "") If Len(strPhone) = 6 Or 7 Then strPhone = Mid(strPhone, 1, 4) & " " & Mid(strPhone, 5, Len(strPhone) - 4) TextBox9.Text = strPhone Else MsgBox TextBox6.Text & " is not a valid postcode. Please enter a valid postcode.", vbOKOnly, "Invalid postcode" TextBox9.Text = "" TextBox9.SetFocus Cancel = True End If End Sub
joe




Reply With Quote