質問

Password validation is getting failed for intRange. The validations are done using the Validator framework. The required validation for password is working fine and displaying the message properly. But the intRange validation is getting failed. Even if the password range is between 4 to 8, the validation message is getting displayed.

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... ints. In a range.

Second, you should name the validator in its argn elements.

If you want to validate length, use the minLength and maxLength validators:

<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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top