[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Random passwords and E-mail regex
> Regular expression for E-mail address checking - here's what I came up
> with. I have not tested it yet, and am not extremely familiar with
> regexes. Anyone want to take a look and see if it can be improved upon?
>
> if (!ereg("^\w+@\w+\.\w+$", $email))
>
> (this is PHP remember, not Perl. Hopefully the regex syntax is the
> same)
I can have a . or - in my username. Similarly, I can have more than two
words
in my domain -- the above limits you to foo@bar.baz.
Try \w[-.\w]* for the things on each side of the @, as a start. Probably
you'll want to consider adding + and similar, for people who sort their
mail like that. (\w == alphanumeric plus underscore, in my perl world.)
Domains can be checked more thoroughly, by checking if it's either 2 or 3
letters, and if 3 if it's a standard one. And beyond that, you can actually
verify the existence of the domain if you like. But that gets trickier to
keep robust.
--Roger