Rauf-
Are you doing client or server-side validation? Or both?
W.R.T your multiple errors, there is an attribute you can set in your
struts XML file, namely:
| <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validations.xml"/>
<set-property property="stopOnFirstError"
value="true"/>
</plug-in>|
Note that you must be using Struts >= 1.2.0 for this feature, though I
believe prior to 1.2.0, the behavior was to always stop on the first error.
I'm a little confused by your explanation but it sounds like you're
possibly missing the XML in your JSP for the email field since you say
it doesn't show up - the other rationale is that it's a valid email address.
Also, just an FYI, your password field does not have a max/min length
validation.
-Adam
Rauf Khan wrote:
Hi,
I am trying to validate a simple form which has a name, password &
email field. I have validated that name field(html:text) should
contain only characters, password field(html:text) contains only
numbers & email field(html:text) should contain proper email id.
When i enter only numbers in name field, only characters in password
field & an invalid email id then only alert msg "please enter only
characters"
is coming for name field & msg "pls enter only numbers for password
field' *BUT* no msg is coming for email field even though i have
entered a wrong email id. Also those two msgs are coming
simultaneously but i want like this, i mean to say when i click on
submit button first only msg for name field should show. Then again if
i click submit button then msg for password field should show & so on.
Also suppose if i enter the proper name (only characs) , proper
password (only numbers) & if i enter the invalid email id then it will
show the
msg" please enter a valid email address".
I am sending the following code for reference :
Validation.xml
---------------------
<!-- compose form Validation-->
<form name="InfoForm">
<field property="fname"
depends="required,mask,minlength,maxlength">
<arg key="ComposeForm.fname" position="0"/>
<msg name="mask" key="ComposeForm.OnlyChars"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</var-value>
</var>
<msg name="minlength" key="ComposeForm.fname.minlength"/>
<arg name="minlength" key="${var:minlength}" resource="false"
position="1"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
<msg name="maxlength" key="ComposeForm.fname.maxlength"/>
<arg name="maxlength" key="${var:maxlength}" resource="false"
position="2"/>
<var>
<var-name>maxlength</var-name>
<var-value>6</var-value>
</var>
</field>
<field property="password" depends="required,mask">
<arg key="ComposeForm.password" position="0"/>
<msg name="mask" key="ComposeForm.OnlyNumbers"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9]*$</var-value>
</var>
</field>
<field property="email" depends="required,email">
<arg key="ComposeForm.email" position="0"/>
<msg name="email" key="ComposeForm.InvalidEmail"
position="0"/>
</field>
</form>
MessageResources.properties:
--------------------------------------------------
#- validations for compose.jsp --
ComposeForm.fname = Please enter the Name.
ComposeForm.password = Please enter the Password.
ComposeForm.email = Please enter the Email.
ComposeForm.OnlyNumbers = Please enter only numbers
ComposeForm.OnlyChars = Please enter only characters
ComposeForm.InvalidEmail = Please enter a valid Email address.
ComposeForm.OnlyNumbersChars = Please enter only numbers & characters
ComposeForm.fname.minlength = First Name cannot be less than {1}
characters.
ComposeForm.fname.maxlength = First Name cannot be greater than {2}
characters.
Thanks in advance.
Regards
Rauf Khan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]