You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ferruh Zamangör <fe...@nterra.com> on 2007/04/23 14:17:21 UTC

Struts Validation Problems

Hi,

I have some problems with using the following regular expression in the validation framework from Struts. 

<field property="projectNumber" depends="required,mask">
			<msg name="mask" key="errors.format"/>
			<arg key="projectNumber" />		
			<arg key="GB-XXXXXX-AA-BB-CC-DD-EE" resource="false" position="1"/>
			<var>
	        	<var-name>mask</var-name>
	        	<var-value>^\w{2}-\w{6}(-\w{2}){0,5}$ | ^[0-9]{4,6}$</var-value>
	        </var>
	     </field>	

I have tested with the following scenarios:

333 ==> validation works and a validation message is displayed.
6666 ==> validation OK
1234567 ==> validation does not work, no validation error is displayed

When I use the same pattern in a java class it works fine???


String input = "1234567";
String pattern = "^\\w{2}-\\w{6}(-\\w{2}){0,5}|([0-9]{4,6})$";
Pattern p = Pattern.compile(pattern);
Matcher match = p.matcher(input);
boolean result = match.matches();


Can anybody tell me what is wrong in the above definition of the field ??

Regards
Ferruh

RE: Struts Validation Problems

Posted by "Raghupathy, Gurumoorthy" <Gu...@nielsen.com>.
"^\w{2}-\w{6}(-\w{2}){0,5}$ | ^[0-9]{4,6}$"
"^\\w{2}-\\w{6}(-\\w{2}){0,5}|([0-9]{4,6})$";

Are different.... you are missing the ^ sign after the | operator...
Please read the regular expression book properly ......





-----Original Message-----
From: Ferruh Zamangör [mailto:ferruh.zamangoer@nterra.com] 
Sent: 23 April 2007 13:17
To: user@struts.apache.org
Subject: Struts Validation Problems

Hi,

I have some problems with using the following regular expression in the validation framework from Struts. 

<field property="projectNumber" depends="required,mask">
			<msg name="mask" key="errors.format"/>
			<arg key="projectNumber" />		
			<arg key="GB-XXXXXX-AA-BB-CC-DD-EE" resource="false" position="1"/>
			<var>
	        	<var-name>mask</var-name>
	        	<var-value>^\w{2}-\w{6}(-\w{2}){0,5}$ | ^[0-9]{4,6}$</var-value>
	        </var>
	     </field>	

I have tested with the following scenarios:

333 ==> validation works and a validation message is displayed.
6666 ==> validation OK
1234567 ==> validation does not work, no validation error is displayed

When I use the same pattern in a java class it works fine???


String input = "1234567";
String pattern = "^\\w{2}-\\w{6}(-\\w{2}){0,5}|([0-9]{4,6})$";
Pattern p = Pattern.compile(pattern);
Matcher match = p.matcher(input);
boolean result = match.matches();


Can anybody tell me what is wrong in the above definition of the field ??

Regards
Ferruh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org