Can someone please document better how the regex field validation works?
The documentation is very vague. All it shows as reference is the following:
regex Match a regular expression regex[/^exp.*?ine$/]
Is the regex contained inside the // like this? regex[/my regex/]
Or what format exactly has this to be followed? The reason is that I’m testing different regex and they all give an Expression Engine error.
Example, something like this work
regex[/^\d{5}$/]
That matches 5 digits but I’m trying to validate a hostname or a valid FQDN name. Examples are: host.host.com host.host.host.tld host.host-host3343.com
I think you get the idea but the problem is that every single regex I tested and tried makes Expression Engine go into error.
Examples are here: https://www.regextester.com/23
Or here: https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
Nothing seems to work. I think it would be really helpful to have some more documentation on this because while the build validation inputs are really amazing without being able to use the regex it severely limits what you can do with validation input. And we all know that EE biggest features is security. Making proper documentation so developers can validate and sanitize their inputs is a priority.
I would really would love to see some examples, at least then we are aware what is accepted and not. Some regex compositions I tested and give error with Expression Engine work fine if I just use PHP code using the preg_match function. Why do the same fail with EE is beyond me. Example is this for example:
/^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9-][a-zA-Z0-9]).)([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$/
Works on PHP but with EE I get:
Exception Caught Unknown validation rule “.
Validator.php:354
This means something on EE is different.
It seems this a bug with the CodeIgniter bug caused by using | on the regex.
I found this:
https://stackoverflow.com/questions/13804721/regex-match-in-codeigniter-form-validation-generates-message-preg-match-no
Ironically, the solution points to an Ellis Lab forums which don’t exist anymore. That means other EE users also had the same issue while using regexes.
Since that forum is gone, (valuable information is lost from Expression Engine…) It would be nice to know what the current state and solution for this is currently.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.