email format in python
Jorgen Grahn
jgrahn-nntq at algonet.se
Tue Jul 19 12:33:35 EDT 2005
On Mon, 18 Jul 2005 06:44:36 -0400, Benji York <benji at benjiyork.com> wrote:
> met at n wrote:
>> I want to have the python equivalent function of this
>> (that checks email format)
>>
...
>> if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+",
...
>
> While it is possible to translate the above code into Python (see
> http://docs.python.org/lib/module-re.html), you should know that the
> regex above will not validate all possible email addresses.
To be even more explicit about it, the regexp is extremely naive, and gives
the wrong results for a lot of common address formats -- not to mention for
even more uncommon formats. Do not use it, and do not try to modify it to
work!
> In general
> it is a fools errand to try to anyway.
Agree. In the case of user input validation, it might be ok to politely
inform the user that the address looks a bit funny, but refusing to work
with it will anger a user sooner or later.
/Jorgen
--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
More information about the Python-list
mailing list