I am validating the decimal places with precision (5,2) which can have negative numbers using regular expresion in struts.
When I try to run this ^[-+]?[0-9]{1,3}+(\.[0-9]{1,2})$
in java it is working fine. But, the same expression in struts is throwing below error.
org.apache.struts.validator.FieldChecks processFailure mask validation failed for property inputCost: org.apache.oro.text.MalformedCachePatternException: Invalid expression: ^[-+]?[0-9]{1,3}+(\.[0-9]{1,2})$
Nested repetitions *?+ in expression
Here is the code snippet of validation.xml.
<field property="inputCost" depends="double,mask">
<arg position="0" key="label.inputCost"/>
<msg name="mask" key="label.inputCost.mask"/>
<var>
<var-name>mask</var-name>
<var-value>^[-+]?[0-9]{1,3}+(\.[0-9]{1,2})$</var-value>
</var>
</field>
Any inputs are greatly appreciated.
Your regex is technically incorrect. You can’t have a
+after a{,}qualifier, it’s like saying.*+or.?*(the+is a special metacharacter in regex meaning “one or more”, just like*means “zero or more”).Try
Notice the
{1,3}+is just a{1,3}.