Closed (fixed)
Project:
Webform Validation
Version:
7.x-1.x-dev
Component:
Validation rules
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
5 Mar 2011 at 08:59 UTC
Updated:
24 Feb 2016 at 18:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
svendecabooterGood idea :)
I'm not regex wizard though, so some thought will have to go into something like this.
I'm postponing this for now unfortunately, as I don't see myself implementing this any time soon realistically...
Comment #2
DrewMathers commentedsvendecabooter,
I too look at regular expressions and see punctuation barf. A Google search on this problem has not revealed an answer. However, the people who dream in regular expressions have assembled a library of patterns you could use to create dozens of specialized validations (e.g. Danish phone number, Austrian postal code, etc.)
Comment #3
DrewMathers commentedHere is a patch that adds this feature.
I chose to use the replacement characters @ and # because this is what the Geonames module gets from the Geonames.org database of international postal code patterns. I had ideas of integrating this with Webform Validation, but it requires a Postal Code field to be dependent on Country field, similar to #917020: Make component(s) required depending on the value of another field
Comment #4
DrewMathers commentedReplaced my ugly PHP version detection hack.
Comment #5
DrewMathers commentedI have re-done this patch as sub-module rather than patching Webform Validation code.
Comment #6
DrewMathers commentedHere is a version of the Pattern sub-module for Drupal 7
Comment #7
liam morlandPlease don't include license files; they are added automatically by the drupal.org packaging script.
If this becomes part of Webform Validation, it would be part of core, not a separate module, so the patch should be made up that way.
I am hesitant to make up a new pattern matching language, even if it is simple. I note that the Geonames database uses | like rexeg does, but your patch treats | as a regular character. Is there a preexisting simple pattern language we could use as a reference to avoid creating yet another standard?
Comment #8
liam morlandComment #9
DrewMathers commentedLiam,
There is a D6 version (comment #4) that implements this in Webform Validation core. However, I got the impression that svendecabooter intended new validators to be separate modules.
Usually applications just make up their own wildcard languages. The only one I know that is an official standard is Wildmat which is now part of NNTP. Good catch on the Geonames use of the OR operator. I missed that.
Thoughts?
Comment #10
liam morlandI would accept this as an additional validator. Please make a patch implementing this along side the other validators in the core module. If it is not too difficult, allowing the OR operator would create alignment with Geonames and would increase the versatility of this validator. Please use _webform_validation_preg_quote() which takes care of the PHP 5.3 version detection.
Comment #11
DrewMathers commentedHere is the patch as reqested above.
Comment #12
liam morlandThanks for the patch. There are some coding standards issues with it. Please review the module with Coder Review. Remove the @diag.
Can you come up with an example other than postal codes? I plan to write an integration with the Postal Code validation module, which does a more precise job than can be done with simple pattern matching.
Comment #13
DrewMathers commentedThis version of the patch passes Coder Code Review. I wanted to keep at least the UK Postal Code example in the help text because it is a real world example of the use of the OR operator.
Comment #14
liam morlandWhat are the brackets for in this regex and why it is so complicated? I don't think we need to do whitespace removal. Wouldn't it work to just replace "\|" with "|"?
Files should always end with a end-of-line character to avoid "\ No newline at end of file" messages.
Comment #15
DrewMathers commentedThe whitespace removal around the "|" is essential. All validation tests fail without it. Consider "pattern1 \| pattern2". Directly substituting "\|" wtih "|" leaves a space after pattern1 and a space before pattern2. Regex treats these spaces being included in the pattern. The user's form entry will never include them, so validation always fails.
The brackets are my abundance of caution owing to the low order of precedence of the OR operator. It might be possible to omit them, but I didn't feel like risking it.
I guess there is no End of Line character at the end of webform_validation_validators.inc. I'll put in a feature request ;)
Comment #16
liam morlandWhat if the space is part of the pattern? People should separate pattern options with a pipe by itself, not surrounded by spaces.
Your patch removes the EOL character from webform_validation_validators.inc.
Comment #17
DrewMathers commentedIt is not possible to submit form data with a leading or trailing space. Webform trims them, even for textarea fields.
Is the EOL a blocker issue to committing this patch?
Comment #18
liam morlandRight about space trimming. Thanks.
The EOL is not blocking it. Your patch also added trailing whitespace. In both cases, my editor removes them automatically.
Comment #19
liam morlandhttp://drupalcode.org/project/webform_validation.git/commitdiff/365bccd
Comment #20
liam morlandComment #21
DrewMathers commentedI know this is a day late and a dollar short but further testing on whitespace trimming showed something interesting. Even though form data ends up trimmed in Webform's output, it arrives into Webform Validator un-trimmed. However, I don't think this has any implications for the Pattern validator.
Comment #22
DrewMathers commentedD6 backport patch
This backport has a dependency on
#1122982-6: Words blacklist regex restriction
Comment #23
liam morlandDrupal 6 is no longer supported.