Hi,
Is it possible to do validation on forms to see if it contains certain text?
I want to reject any message that has gmail in the email address, or http in the main body.
Is that doable?
Thanks
Antony
-
☆ A M B ☆
- 24,524 Posts
Yes, this can be done in at least two different ways:
1. Use the field validation attribute; see the documentation for specifying a regular expression in the validation field of the eform attribute.
# #REGEX - regular expression - syntax as for preg_match() - see php manual
example: #REGEX /^[a-z]+ [a-z0-9_]+/i
2. Use a custom snippet with a function to be used with eform’s &eFormOnValidate event.
# &eFormOnValidate (optional)
Expects a function name. This function will be called directly after the form validation has taken place. You can use this event to add your own extra validation logic. The function should accomodate the following parameters
* &$fields - (as reference) an associative array of field and placeholder values.
* &$vMsg - (as reference) a numeric array of validation error messages.
* &$rMsg - (as Reference) a numeric array of missing required fields.
Thanks for the response.
Regex is something that I have great difficulty with.. have been trying to have a stab, but failing.
I worked out this:
eform="Message:string:1:required field or invalid characters:#REGEX /[^http]/"
would block any string beginning with http. However, how do I match that to anywhere in the string?
Thanks
Sorry to bump my own post, but can anyone help with my regex query?
It’s an area I can’t really get my head around.
Thanks