PatternValidator could allow reverse matches
--------------------------------------------
Key: WICKET-2186
URL: https://issues.apache.org/jira/browse/WICKET-2186
Project: Wicket
Issue Type: Improvement
Components: wicket
Affects Versions: 1.4-RC2
Reporter: John Patterson
I need to define a pattern which is invalid as form field input. i.e. I have a
user feed back from that receives a lot of spam but the names are normally
something like "xtrqkjitvxqoh". Instead of having a capture I want to set
names with 5 successive consonants as invalid.
This patch does the trick...
Index:
src/main/java/org/apache/wicket/validation/validator/PatternValidator.java
===================================================================
--- src/main/java/org/apache/wicket/validation/validator/PatternValidator.java
(revision 749072)
+++ src/main/java/org/apache/wicket/validation/validator/PatternValidator.java
(working copy)
@@ -64,6 +64,9 @@
/** the <code>java.util.regex.Pattern</code> */
private final Pattern pattern;
+ /** whether to exclude matching input **/
+ private boolean reverse;
+
/**
* Constructor that accepts a <code>String</code> regular expression
pattern.
*
@@ -111,6 +114,15 @@
this(pattern.pattern());
}
+ /**
+ * If set to true then input that matches the pattern is considered
invalid.
+ *
+ * @param reverse
+ */
+ public void setReverse(boolean reverse)
+ {
+ this.reverse = reverse;
+ }
/**
* Gets the regexp pattern.
@@ -155,7 +167,7 @@
protected void onValidate(IValidatable<String> validatable)
{
// Check value against pattern
- if (!pattern.matcher(validatable.getValue()).matches())
+ if (pattern.matcher(validatable.getValue()).matches() ==
reverse)
{
error(validatable);
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.