You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Juergen Donnerstag (JIRA)" <ji...@apache.org> on 2009/04/07 16:06:12 UTC

[jira] Resolved: (WICKET-2186) PatternValidator could allow reverse matches

     [ https://issues.apache.org/jira/browse/WICKET-2186?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Juergen Donnerstag resolved WICKET-2186.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.4-RC3
         Assignee: Juergen Donnerstag

applied thanks

> 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
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4-RC3
>
>
> 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.