You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Siddiq Syed <si...@yahoo.com> on 2009/05/13 21:31:31 UTC

Trim for regex validator is not working

Hi all,

Do anybody have an idea why this is not working.
There is validation for a numeric field which is a string in the action ,
The validation is through regular expression as show below.

<field name="caseNumber">
	<field-validator type="requiredstring">
		<message>Please enter a case number</message>
	</field-validator>
	<field-validator type="regex">
  		[0-9]{1,}
 	    <message>Please enter a valid case number</message>
	</field-validator>	
</field>

As per struts  
http://struts.apache.org/2.1.6/docs/regex-validator.html  the default value
for trim is true,

The problem is validation is not happening if I give a space either at the
begining or at the ending of the case number in the text filed, basically
trim is not working for this field.

Do any body have any idea how to set trim to work. Or any other regular
expression where it can trim the the white spaces.

Thanks in advance.

Regards
Siddiq. 

-- 
View this message in context: http://www.nabble.com/Trim-for-regex-validator-is-not-working-tp23528434p23528434.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Trim for regex validator is not working

Posted by Siddiq Syed <si...@yahoo.com>.
Thanks Dave,

In order to dispaly the error message if we give the whitespace infront of
the number , we need to set trim="false".

I sloved this problem by setting trim="false" for regex validation. Below is
the snippet.

Thanks a lot for you input.

<field name="caseNumber">
	<field-validator type="requiredstring">
		<message key="initializeCase.caseNumber.required"/>
	</field-validator>
	<field-validator type="regex">
		false
  		[0-9]{1,}  		
  		 <message key="invalid.fieldvalue.caseNumber"/>
	</field-validator>	
</field>

Regards
Siddiq.


newton.dave wrote:
> 
> Siddiq Syed wrote:
>> I am searching for the regular expression, which ignore white spaces but
>> no
>> sucess so far.
>> 
>> Any idea ?
> 
> ...
> 
> According to [1] (which was the top hit when I searched for "java 
> +regular expression), "\s" matches any whitespace character. "*" means 0 
> or more occurrences. So \s* would match any number of whitespace 
> characters. This, of course, isn't a Struts issue.
> 
> When I did the afore-mentioned search it returned *many* Java regular 
> expression tutorials; I am skeptical that none of them contained this 
> information.
> 
> You may wish to read [2], which is Sun's regex tutorial. It was among 
> the top-most hits when searching. It included this information.
> 
> Dave
> 
> [1] http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
> [2] http://java.sun.com/docs/books/tutorial/essential/regex/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Trim-for-regex-validator-is-not-working-tp23528434p23602881.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Trim for regex validator is not working

Posted by Dave Newton <ne...@yahoo.com>.
Siddiq Syed wrote:
> I am searching for the regular expression, which ignore white spaces but no
> sucess so far.
> 
> Any idea ?

...

According to [1] (which was the top hit when I searched for "java 
+regular expression), "\s" matches any whitespace character. "*" means 0 
or more occurrences. So \s* would match any number of whitespace 
characters. This, of course, isn't a Struts issue.

When I did the afore-mentioned search it returned *many* Java regular 
expression tutorials; I am skeptical that none of them contained this 
information.

You may wish to read [2], which is Sun's regex tutorial. It was among 
the top-most hits when searching. It included this information.

Dave

[1] http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
[2] http://java.sun.com/docs/books/tutorial/essential/regex/

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


Re: Trim for regex validator is not working

Posted by Siddiq Syed <si...@yahoo.com>.
Hi Dave, 

I tried setting trim="true" , I donno why some how its not working.

I am searching for the regular expression, which ignore white spaces but no
sucess so far.

Any idea ?

Thanks
siddiq.


newton.dave wrote:
> 
> Siddiq Syed wrote:
>> Do anybody have an idea why this is not working.
>> There is validation for a numeric field which is a string in the action ,
>> The validation is through regular expression as show below.
>> 
>> <field name="caseNumber">
>> 	<field-validator type="requiredstring">
>> 		<message>Please enter a case number</message>
>> 	</field-validator>
>> 	<field-validator type="regex">
>>   		[0-9]{1,}
>>  	    <message>Please enter a valid case number</message>
>> 	</field-validator>	
>> </field>
>> 
>> As per struts  
>> http://struts.apache.org/2.1.6/docs/regex-validator.html  the default
>> value
>> for trim is true,
>> 
>> The problem is validation is not happening if I give a space either at
>> the
>> begining or at the ending of the case number in the text filed, basically
>> trim is not working for this field.
>> 
>> Do any body have any idea how to set trim to work. Or any other regular
>> expression where it can trim the the white spaces.
> 
> Did you try setting trim to true?
> 
> Any reasonable regex tutorial will give you the syntax for ignoring 
> arbitrary quantities of whitespace.
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Trim-for-regex-validator-is-not-working-tp23528434p23529634.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Trim for regex validator is not working

Posted by Dave Newton <ne...@yahoo.com>.
Siddiq Syed wrote:
> Do anybody have an idea why this is not working.
> There is validation for a numeric field which is a string in the action ,
> The validation is through regular expression as show below.
> 
> <field name="caseNumber">
> 	<field-validator type="requiredstring">
> 		<message>Please enter a case number</message>
> 	</field-validator>
> 	<field-validator type="regex">
>   		[0-9]{1,}
>  	    <message>Please enter a valid case number</message>
> 	</field-validator>	
> </field>
> 
> As per struts  
> http://struts.apache.org/2.1.6/docs/regex-validator.html  the default value
> for trim is true,
> 
> The problem is validation is not happening if I give a space either at the
> begining or at the ending of the case number in the text filed, basically
> trim is not working for this field.
> 
> Do any body have any idea how to set trim to work. Or any other regular
> expression where it can trim the the white spaces.

Did you try setting trim to true?

Any reasonable regex tutorial will give you the syntax for ignoring 
arbitrary quantities of whitespace.

Dave


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