>>The Regular Expression parser from the Windows Script Host makes this a snap. In fact, this was one of the problems that Ed Rauh and I addressed in our final article on the WSH in past March's issue of the VFUG (
www.vfug.org) newsletter. All you need is
oRE = CREATEOBJECT("VBScript.RegExp")
>>oRE.Pattern = "\w+\@\w+\.\w+"
>>llresult = oRE.Test(tceMailAddr)
The article and the one's that preceded it are available on-line at VFUG.
>
>Try this pattern, it allows for "-" and "_" in the emails.
>oRE.Pattern = "[\w-_]+\@{1}[\w-_]+\.\w+"
First, the underscore ("_") is included in the set defined by the "w" character. So it is superfluous. Further, the "@{1}" is also superfluous, since by definition, "\@" defines a single, non-repeating occurance of the character. That only leaves the hyphen.
If it appears in the address name, prior to being the last character preceeding the "@", the expression will evaluate to be correct. For example, and using the pattern I supplied,
? oRE.Test("george-tasker@domain.com")
returns .T. The matches collection returned by the Execute method shows this:
oMatches = oRE.Test("george-tasker@domain.com")
FOR EACH oMatch IN oMatches
? oMatch.Value
NEXT
The only place, therefore, that the hyphen might come into play is in the domain.
Admittedly, I don't know enough about the allowable characters in the domain name to say whether or not this will be a problem. I will say, however, that the example similar to the one in the book "The Windows Script Host Programmers Reference" by Dino Esposito, published by Wrox Press.
What I tried to do was provide an example that would cover the vast majority possible email addresses. This I did. If I wished to pick at it, I could point out that the suffix of the domain should be three alphabetic characters and might more precisely be defined as: [A-Za-z]{3}, which would give the pattern "\w+\@\w+\.[A-Za-z]{3}"
George
Ubi caritas et amor, deus ibi est