this codes validates phone numbers so if the user inputs the number in as 01159313481 or 0115 9313481 it accepts it and anything else it dosnt. the only problem i have is that it dosnt check if the space is in the right place, for example the user can put in 01159 313481 and it is accepted, any ideas?
Private Sub TextBox4_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Text = Trim(TextBox4.Text)
If TextBox4.TextLength = 11 Then
Dim position
position = InStr(5, TextBox4.Text, " ")
If position = 0 Then
spacedpost = TextBox4.Text
TextBox4.Text = Mid(spacedpost, 1, 4) & " " & Mid(spacedpost, 5, Len(spacedpost) - 4)
Else: MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
End If
Exit Sub
ElseIf TextBox4.TextLength = 12 Then
Dim position1
position1 = InStr(5, TextBox4.Text, " ")
If position1 = 0 Then
MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
ElseIf position = 1 Then
End If
Exit Sub
Else: MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
TextBox4.SetFocus
Cancel = True
End If
End Sub
any help is much appreciated
Joe
