Form::PATTERN doesn't allow for case-insensitive checks
renekliment opened this issue · comments
Version: 2.4.x
Bug Description
Hi! I'm trying to perform a case-insensitive pattern validation using the Form::PATTERN
form rule, but it seems the functionality isn't there.
- Both the PHP & JS code puts stuff before and after the regexp so using global modifiers is not possible. Moreover, JS doesn't support in-line regexp modifiers.
- It seems that
Form::REGEXP
used to exist in the past (but was removed) that could do this. Also, innetteForms.js
, the handler function is still there.
Steps To Reproduce
$control->addRule(Form::PATTERN, 'Invalid file extension.', "(.*)\.(txt|md)");
Expected Behavior
To be able to use the i
modifier. Or to be able to achieve the same behavior in a reasonable way.
Possible Solution
Not sure. I don't know the reason behind removing Form::REGEXP
and it seems weird to me that people wouldn't want to use this. Do they write new validation rules instead?
It should be compatible with HTML5 attribute pattern
@dg I see, makes sense. What was the reason for removing Form::REGEXP
then? Duplicity? If that's the case and the only reason, I believe it would be beneficial to bring it back, because it provides an added value. I can open a PR if it makes sense.
Yes, duplicity.
Because REGEXP had a little different syntax, it might be better to add new PATTERN_ICASE
(or similar name).
@dg Okay, I'll try to cook up a PR. Thank you.