Click to See Complete Forum and Search --> : Regular expressions, anyone?


Cakkie
December 3rd, 2002, 03:02 PM
Anyone know how to build the pattern?
I'm trying to validate an email address in the form of user@host. I don't even need the tld part (.com, .be, .net).

I read the helpfile topic in that, which explains things, but when I try to match, it always returns true.

This is the pattern I though it should be...
[a-zA-Z0-9\-\._]+\@[a-zA-Z0-9\-\._]+

the first part [a-zA-Z0-9\-._]+ would be the part before the @, containing at least 1 character from a-z, A-Z, 0-9, dash (\-), dot (\.) or underscore (_).
the same goes for the last part.
The middle is just an escaped @, to match the @ sign.

The problem is that it matches any string that has at least one charecter before and after the @ sign, no matter what.

I think I need an expression that only give these where all characters match.

Examples of addresses with the value it should be, and what it gives me

user@host : true, gives true
user@host@host: false, gives true
us#er@host: false, gives true
@user.host: false, gives false


Anyone know what expression I should use, and knows why that is?

Athley
December 3rd, 2002, 03:22 PM
There are quite a few sites that discuss this if you search the web.... Here's one....

Link (http://www.breakingpar.com/bkp/home.nsf/Doc!OpenNavigator&87256B280015193F87256C40004CC8C6)

....or try this....

"^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$"

/Leyan