A little piece of Python code for specific email validation?

1 message Options
Embed this post
Permalink
Lars Löwenadler () A little piece of Python code for specific email validation?
Reply Threaded More More options
Print post
Permalink
Hi,

Seems like PloneFormGen generates many questions at this forum. Here's another one (two actually)...

Using Plone 3.3.1 on Windows:

In a PloneFormGen form I've built, and the join_form (with self registration enabled), I'm looking for validation of specific email address domains rather than just validation of any email address.

From the documentation "Creating Custom Validators" ( http://plone.org/products/ploneformgen/documentation/how-to/creating-custom-validators ) I've found this line:

python: test(value.find('spam')>=0, False, 'Input must include spam.')

I've successfully enabled it for the PFG form with my own data, here's how it looks:

python: test(value.find('@somedomain1.com')>=0, False, 'This e-mail address is not authorized for sending data')

Now my questions are:

1) How can I add more values than just '@somedomain1.com', e.g. '@somedomain2.com' ? I'm lacking Python knowledge and I can't figure out how to do this, despite trying to read documentation basics. I would guess this is doable, but typing them e.g. comma separated ('@somedomain1.com', '@somedomain2.com') won't work.

2) As I have issues understanding how custom validators made in ZMI works, I'd like to use this expression also for the join_form. Provided that this is not a bad idea from a security perspective, how can I do this? I've added the following tag to the e-mail field in join_form:

<tal:email condition="python: test(value.find('@somedomain1.com')>=0, False, 'This e-mail address is not authorized for registering a website account.')">

It won't work though, when visiting join_form the error log says "Exception Value   name 'value' is not defined". What does this mean?

Any input would be much appreciated.

Thanks
Lars