简体   繁体   English

Struts 1.2 intRange验证失败

[英]Struts 1.2 intRange Validation getting failed

Password validation is getting failed for intRange. intRange的密码验证失败。 The validations are done using the Validator framework. 验证使用Validator框架完成。 The required validation for password is working fine and displaying the message properly. 密码所需的验证工作正常并正确显示消息。 But the intRange validation is getting failed. 但是intRange验证失败了。 Even if the password range is between 4 to 8, the validation message is getting displayed. 即使密码范围在4到8之间,也会显示验证消息。

Below is the code: 以下是代码:

<field property="password" depends="required,intRange">

            <arg0 key="error.password.required" />
            <arg1 key="${var:min}" resource="false"/>
            <arg2 key="${var:max}" resource="false"/>
            <var>
                <var-name>min</var-name>
                <var-value>4</var-value>
            </var>
            <var>
                <var-name>max</var-name>
                <var-value>8</var-value>
            </var>

        </field>

This entry is present in the resources properties file: 此条目存在于资源属性文件中:

errors.range={0} is not in the range {1} through {2}.

Irrespective of the size of the password input, the message is getting displayed. 无论密码输入的大小如何,都会显示消息。

I might be missing something but unfortunately not able to figure it out :( 我可能会遗漏一些东西,但遗憾的是无法解决这个问题:(

Please let me know about this. 请让我知道这件事。

Regards, 问候,

First, intRange is for validating... int s. 首先, intRange用于验证... int s。 In a range. 在一个范围内。

Second, you should name the validator in its argn elements. 其次,您应该在其argn元素中命名验证器。

If you want to validate length, use the minLength and maxLength validators: 如果要验证长度,请使用minLengthmaxLength验证器:

<field property="name" depends="required,minlength,maxlength">
    <arg0 key="error.password.required" />
    <arg1 name="minlength" key="${var:minlength}" resource="false"/>
    <arg2 name="maxlength" key="${var:minlength}" resource="false"/>
    <var><var-name>minlength</var-name><var-value>4</var-value></var>
    <var><var-name>maxlength</var-name><var-value>8</var-value></var>
</field>

You could also use a mask , better if you have any specific character requirements, too. 如果你有任何特定的角色要求,你也可以使用mask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM