albertc30
Well-known Member
- Joined
- May 7, 2012
- Messages
- 1,091
- Office Version
- 2019
- Platform
- Windows
Hi all.
I want to validate a textbox to confirm email has been entered correctly.
I remember this being an issue in the past and it seems it still is.
I have been using the code bellow and was feeling that, I don't want the OK message if the email is okay but rather want a user message asking if the entered email (display email on message) is correct? YES (Continue) NO (returns to email field.)
Again, much appreciated for all your time and help.
Cheers
I want to validate a textbox to confirm email has been entered correctly.
I remember this being an issue in the past and it seems it still is.
I have been using the code bellow and was feeling that, I don't want the OK message if the email is okay but rather want a user message asking if the entered email (display email on message) is correct? YES (Continue) NO (returns to email field.)
Code:
[COLOR=#333333]Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)[/COLOR]
[COLOR=#333333]With CreateObject("vbscript.regexp")[/COLOR]
[COLOR=#333333]'.Pattern = "^[\w-\.]+@([\w-]+\.)+[A-Za-z]{2,4}$"[/COLOR]
[COLOR=#333333].Pattern = "^[\w-\.]+@[\w-]+\.+[A-Za-z]{2,4}$"[/COLOR]
[COLOR=#333333]If .test(TextBox1.Value) Then[/COLOR]
[COLOR=#333333]MsgBox "OK"[/COLOR]
[COLOR=#333333]Else[/COLOR]
[COLOR=#333333]MsgBox "No good"[/COLOR]
[COLOR=#333333]Cancel = True[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End With[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
Again, much appreciated for all your time and help.
Cheers