带有最小值和最大值的 int fieldvalidatorstruts2 的验证不正确
在我的struts2应用程序中,我有一个带有“phone”字段的jsp页面,我已经使用
<field-validator type="int">
<param name="min">4</param>
<param name="max">20</param>
<message key="errors.range"/>
</field-validator>
int类型min和max应用了验证,但对我来说没有验证,当我尝试给出正确的更大值时,它给出了负数超过 4 个数字
是我的 jar 文件
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
In my struts2 application , I have a jsp page with "phone" field 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
呃...您正在尝试验证电话号码值是否在“4”和“20”之间???
我猜您正在尝试验证电话长度(作为字符串)是否在 4 到 20 之间,这是完全不同的事情。查看 字符串长度验证器
并记住:仅适用于凡人“电话号码”是一个数字。对于程序员来说,“电话号码”不是一个数字,而是一个字符串(由数字和可能还有一些附加字符组成)。信用卡号或邮政编码也是如此。经验法则:如果你可以想象你会用它做一些算术(比如求和),那么它就是一个数字。如果(即使是假设的)要保留前导零,或者如果它可能包含一些非数字字符,那么它不是数字而是字符串。
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.
也许您应该尝试使用正则表达式,这里有一个示例,
链接可以帮助 http://www.itinpractice.com/tutorials/397/struts-2-form-validation-using-xml.html
Maybe you should try a regular expression, here's an example
that link could help http://www.itinpractice.com/tutorials/397/struts-2-form-validation-using-xml.html