tags:

views:

129

answers:

1

Hi

In my struts2 applicaion , i have a jsp page with "phone" feild in it for which i have applied validation using the

<field-validator type="int">
<param name="min">4</param>
<param name="max">20</param>
<message key="errors.range"/>
</field-validator>

int type min and max is not validating for me ,it is giving a negative number when i try to give the correct greater than 4 numbers

here are my jar files

commons-beanutils-1.8.0.jar  
commons-digester-1.8.1.jar  
commons-fileupload-1.2.1.jar  
commons-logging-1.1.jar    
freemarker-2.3.13.jar  
mail.jar  
ognl-2.6.11.jar  
spring.jar  
struts2-core-2.1.6.jar  
struts2-dojo-plugin-2.1.6.jar  
struts2-spring-plugin-2.1.6.jar  
struts2-tiles-plugin-2.1.6.jar  
tiles-api-2.1.2.jar  
tiles-compat-2.1.2.jar  
tiles-core-2.1.2.jar  
tiles-jsp-2.1.2.jar  
tiles-servlet-2.1.2.jar  
xwork-2.1.2.jar 
A: 

uh... you are trying to validate that a phone number value is between '4' and '20' ???

I guess that you are trying to validate that the phone length (as a string) is between 4 and 20, quite a different thing. Look at the String Length validator

And remember: for mere mortals a "phone number" is a number. For programmers, a "phone number" is not a number, but a string (composed of digits and perhaps some additional characters). The same goes for a credit card number or a zip number. A rule of thumb: if it's remotely conceivable that you'll done some arithmetic (say, a sum) with it, it's a number. If (even hypothetical) leading zeroes are to be preserved, or if it might include some non-digits characters, then it's not a number but a string.

leonbloy