Validators: Into the Deep - Registration Form: Putting it All Together
(Page 4 of 4 )
Until now I have simply discussed all of the Validators; now, let's see them in action. For this I will be using a registration form. To keep things simple I will concentrate only on the following fields:
So let's get started. Up until the <form> element everything is the same as the one illustrated in the first part of this series, which is:
< form-validation>
<formset>
<form name=“registrationFormBean”>
:
:
</form>
</formset>
</ form-validation>
The first field is the user name. The rules to be applied are mandatory and the minimum length. The minimum length is three characters.
< form-validation>
<formset>
<form name=“registrationFormBean”>
<field property="userName" depends="required,minlength">
<arg0 key="registration.UserName"/>
</field>
<arg1 name="minlength"
key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
:
:
</form>
</formset>
</ form-validation>
Next comes the Name. Here, apart from the mandatory Validator, the mask Validator will also have to be applied, so that only characters can be entered.
< form-validation>
<formset>
<form name=“registrationFormBean”>
<field property="name" depends="required,minlength">
<arg0 key="registration.UserName"/>
</field>
<arg1 name="minlength"
key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
<field property="Name" depends="required,mask">
<msg name="mask" key="registration.name.maskmsg"/>
<arg0 key="registration.Name"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</var-value>
</var>
<field>
:
:
</form>
</formset>
</ form-validation>
Last but not least is the existing email field. Here mandatory and email validations are required.
< form-validation>
<formset>
<form name=“registrationFormBean”>
<field property="name" depends="required,minlength">
<arg0 key="registration.UserName"/>
</field>
<arg1 name="minlength"
key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
<field property="Name" depends="required,mask">
<msg name="mask" key="registration.name.maskmsg"/>
<arg0 key="registration.Name"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</var-value>
</var>
<field>
<field property="Email" depends="email">
<arg0 key="registration.email"/>
</field>
</form>
</formset>
</ form-validation>
And that brings us to the end of this session of discussion. There are some obvious questions that are left unanswered. These include how to compare and validate the values of two fields such as password, retype password fields, and creating a custom Validator. These will be the topics of the third and last part of this tutorial/discussion series. Until next time.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |