Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using Wildcards

Posted on 2003-03-02
3
Medium Priority
?
301 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

580 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