Quick Visual Basic Question

Associate
Joined
14 Jun 2010
Posts
737
Evening all :)

I have started learning VB today and am in need of a little help.

I am creating a program and I want it to recognise when the user enters @hotmail.com or some other ending for an email address.

As I'm fairly new to the language I was thinking about having a wildcard symbol before the @hotmail. Such as If textbox1.text = "*@hotmail.com" Then

But it appears there is no such function. Can someone please recommend a way for me to do this? Google really hasn't helped much :(

Cheers.
 
It's throwing the error of "Conversion from string "@gmail.com" to type 'Long' is not valid."

the line of code is If TextBox6.Text.EndsWith("@gmail.com" Or "@gmail.co.uk") Then

Any ideas why this is happening? I haven't mentioned Long data types in any of the code. :(
 
AFAIK you can't do "@gmail.com" Or "@gmail.co.uk" in Visual Basic.

EDIT: As above you'd have to make multiple calls to EndsWith or create a more complex function.
 
is there not an "instr" (ing) function??

i.e.
if instr(yourtextbox.text,"@hotmail") then
...do stuff
end if

excuse the syntaxt...i'm a c# fella these days
 
Try

Code:
string test
test = "[email protected]"
bool isEmailAddress = test.Contains("@hotmail.com")
.Contains(string) returns bool (true/false)

I agree tho. that regular expressions (regex) is the way to go. It allows for more varied addresses to be caught.
 
Last edited:
is there not an "instr" (ing) function??

i.e.
if instr(yourtextbox.text,"@hotmail") then
...do stuff
end if

excuse the syntaxt...i'm a c# fella these days

Yes there is an InStr function but EndsWith is the easier option and probably the correct way of doing considering it returns a boolean and checks the end of the string. Ideally the OP should also add some form of email validation (either basic or rfc2822 compliant) which could easily be done using regex.
 
Back
Top Bottom