I'm working at E-mail Sender. I want to make check that is something before @, for example:
If Nothing at left side of "@" Then
MsgBox("Wrong e-mail")
End If
But i have no idea how can i do that, it's possible?
I'm working at E-mail Sender. I want to make check that is something before @, for example:
If Nothing at left side of "@" Then
MsgBox("Wrong e-mail")
End If
But i have no idea how can i do that, it's possible?
Maybe the most efficient way to check @ in an e-mail address is to check the index?
dim email as string = "test@test.com"
dim index as integer = email.IndexOf("@")
if index = -1 OrElse index = 0 then
MsgBox("Wrong e-mail")
End If
When not found its -1
and it should not be index 0.
Note: This does not check if there is nothing before the @, but it does make a basic check for what you try to achieve.
I'd use a regular expression for this and check for more than just the @ to give a more thorough comfort that an actual email address was entered:
Function IsValidEmail(emailAddress As String) As Boolean
Dim regEx As New Regex("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$")
Return regEx.IsMatch(emailAddress)
End Function