I would like to use regular expression in the form created using ploneformgen 1.7. I am using plone 4.1. In the custom validation of a text field.
How do I use the regular expression?
I tried the following:
python: import re; test(value==re.search(r'[123]'), False, 'Needs to be number 1 or 2 or 3')
but it gives me error and hence cannot validate. I want value should be 1 or 2 or 3. I am able to use the expression as
python: test(value=='1' or value=='2' or value=='3', False, 'Needs to be number 1 or 2 or 3')
BUT I would like to use regular expressions. Please guide.
The set of packages and types that you may use in through-the-web scripts, TALES "python:" expressions, PFG overrides and PFG script adapters is limited to those available in Restricted Python. Restricted Python is deliberately very conservative in which modules and types it makes available.
You may expand the list with explicit "allow" declarations made in a Python package included in your egg list. A sample of such a package is available in the github collective, and includes several modules and types that I've found particularly useful in PloneFormGen, including re.
You will still not be able to "import re" in a TALES expression, but you will be able to use re in a TTW script, which may be used as a PFG validator.