?
Solved

Using Wildcards

Posted on 2003-03-02
3
Medium Priority
?
291 Views
Last Modified: 2010-04-17
I am trying to validate whether an e-mail address is in the correct format or not. Why does this not work?

If Trim(txtTo.Text) = "*@*.*" Then
MsgBox "Good"
Else
MsgBox "Bad"
End If

It seems that it always returns bad, unless I actually type "*@*.*". Why are the wildcards not working properly?
0
Comment
Question by:Produkt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 8054169
Wildcards do not work across the = sign.  You need to use a string function that accepts the wildcard.

Wildcards were added for database usage to allow for comparison based on a substring.

What you want to have is code to parse the address to see if meets the proper format.

I think if you look at

http://www.freevbcode.com/ShowCode.Asp?ID=4904

you will find the code you need.

mlmcc
0
 
LVL 3

Accepted Solution

by:
taisk earned 80 total points
ID: 8054245
This is because in VB, text comparison is not wildcardable.  The only time the expression Trim(txtTo.Text) = "*@*.*" is true is, as you suggested, when you actually enter "*@*.*".

What you can do instead is to use the instr command.

e.g.
v = Trim(txtTo.Text)
If InStr(v, "@") > 1 And InStr(v, ".") > InStr(v, "@") + 1 And Mid(v, Len(v), 1) <> "."  Then
MsgBox "Good"
Else
MsgBox "Bad"
End If
0
 

Author Comment

by:Produkt
ID: 8054491
Works perfectly. Thank you.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question