[Zope-CMF] Re: [dev] _checkEmail issues

yuppie y.2006_ at wcm-solutions.de
Fri Oct 20 11:55:35 EDT 2006


Hi Seb!


Seb Bacon wrote:
> Agreed that it's too restrictive.  FWIW we have been using this in
> production.  It was based on careful checking of the various RFCs
> (though I've just noticed it should also restrict the domain name to
> 255 characters):
> 
> _email_rgx = 
> re.compile(r'^([A-Za-z0-9!#$%&\'*+-/=?^_`{|}~][A-Za-z0-9!#$%&\'*+-/
> =?^_`{|}~\.]{0,63}|"[^(\|")]{0,62}")@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$')

I like your regex, but I see two small issues:


1.) The last '-' in '[A-Za-z0-9!#$%&\'*+-/=?^_`{|}~]' has to be escaped. 
I'll use this instead:

'[\w!#$%&\'*+\-/=?^`{|}~]'


2.) '[A-Za-z0-9!#$%&\'*+-/=?^_`{|}~\.]{0,63}' allows '.' in any place. 
I'll use the same pattern as for the domain:

(\.[\w!#$%&\'*+\-/=?^`{|}~]+)*


The complete regex would look like this:

re.compile(r'^([\w!#$%&\'*+\-/=?^`{|}~]+(\.[\w!#$%&\'*+\-/=?^`{|}~]+)*'
            r'|"[^(\|")]*")@[\w-]+(\.[\w-]+)+$')

I can't see a way to combine this pattern with a length check. So I 
would need a second expression to check the length of the two parts.


Does that make sense?

Cheers,

	Yuppie



More information about the Zope-CMF mailing list