Re: email format in python

Discussion in 'Python' started by Benji York, Jul 18, 2005.

  1. Benji York

    Benji York Guest

    met@n wrote:
    > I want to have the python equivalent function of this
    > (that checks email format)
    >
    > function CheckEmail($Email = "") {
    > if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+",
    > $Email)) {
    > return true;
    > } else {
    > return false;
    > }
    > }


    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. In general
    it is a fools errand to try to anyway.
    --
    Benji York
     
    Benji York, Jul 18, 2005
    #1
    1. Advertising

  2. Benji York

    Jorgen Grahn Guest

    On Mon, 18 Jul 2005 06:44:36 -0400, Benji York <> wrote:
    > met@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!
     
    Jorgen Grahn, Jul 19, 2005
    #2
    1. Advertising

  3. Benji York

    Mike Meyer Guest

    Jorgen Grahn <> writes:
    > 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.


    Yup. I use cryptographically signed addresses as one-time addresses
    for web forms. They look like .

    It really annoys me when some site decides that that can't be my real
    email address.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Jul 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. met@n

    email format in python

    met@n, Jul 18, 2005, in forum: Python
    Replies:
    0
    Views:
    302
    met@n
    Jul 18, 2005
  2. Nico Grubert
    Replies:
    0
    Views:
    882
    Nico Grubert
    Dec 8, 2006
  3. rote
    Replies:
    8
    Views:
    778
  4. Wesley
    Replies:
    1
    Views:
    140
    Wesley
    Apr 15, 2014
Loading...

Share This Page