[Zope] Valid email address...

Michael Fox Michael@Wodin.CenturySoftware.com.au
Fri, 12 Apr 2002 17:09:32 +1000


Cheers Max, that's exactly what I needed. Simply to check if the string
contains those values..

something@something.something

The fact that is is or isn't a real email address is not an issue for me
ATM.

Thanks,
Michael.

-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Max M
Sent: Friday, 12 April 2002 4:59 PM
To: Michael Fox
Cc: zope@zope.org
Subject: Re: [Zope] Valid email address...


Michael Fox wrote:

>Not being a python guru myself, I was wondering if anyone could provide
a code snippet that checks the value of a dtml-var to see if it's a
valid email address..?
>

There is no way to do it correctly without sending an email and see if=20
you get an reply, so don't sweat to much over it.

I usually just do something like:

def isValidMail(adress):
    return '@' in adress and '.' in adress

or if you are a bit more paranoid:

def isValidMail(adress):
    if '@' in adress and '.' in adress:
        id, url =3D adress.split('@')
        domain, topDomain =3D url.split('.')
        return len(id)>0 and len(domain)>0 and len(topDomain)>0
    return 0

In practice you cannot really do much better even though you tried much=20
harder.

you could then call it like:

<dtml-if "isValidMail(adress)">
do stuff
</dtml-if>

regards Max M



_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -=20
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )