I'm setting up a simple program in VB and I have a field where the user must input their email. I want to make it so the program requires the '@' symbol in the textbox.
I was thinking that at the end when the user submits their info, if there is no '@', they will receive a msgbox saying the email is not valid. Could I add a variable in the above code so the program checks if it was included or not?
I have previously included some code where only numbers are allowed (in a textbox for a phone number) but I don't know if I could use it as a reference. Not sure if it's needed here but I'll include it anyway
' === code for validating numbers only ===
If Char.IsDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
End If
I am very new to VB still. Thanks!
CodePudding user response:
Below are 2 ways this can be done.
If Not TextBox1.Text.Contains("@") Then
MsgBox("No @ exists...")
End If
or
If InStr(1, TextBox1.Text, "@") = 0 Then
MsgBox("No @ exists...")
End If