On Sep 19, 2006, at 8:31 AM, [EMAIL PROTECTED] wrote:
>
> Hi folks,
>
> I'm trying to add an email validation to my registration form. Is
> there any type of email validator or regex expression I can use?
>
> This site
> (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65215) has
> some python code but apparently it is not very robust.
>
> I think at most basic i just need to regex "[EMAIL PROTECTED]"
>
> What regex forumlas have you guys been using?
There's an Email validator in FormEncode (bundled with TG) which
works like a charm:
>>> from turbogears.validators import *
>>> Email.to_python('[EMAIL PROTECTED]')
'[EMAIL PROTECTED]'
>>> Email.to_python('[EMAIL PROTECTED]')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/FormEncode-0.5.1-py2.4.egg/formencode/
api.py", line 319, in to_python
vp(value, state)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/FormEncode-0.5.1-py2.4.egg/formencode/
validators.py", line 1174, in validate_python
value, state)
formencode.api.Invalid: The domain portion of the email address is
invalid (the portion after the @: foo)
You can use this validator with form widgets. It can also do a dns
lookup for the domain to check if it's valid if you install pyDNS.
HTH,
Alberto
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---