Custom JSP taglib. Provides a client side validation service. Taglib generates an appropriate JavaScript code for checking mandatory fields in your forms. You have to use this taglib with Form tags.
Body tag required lets you define mandatory fields. Let we see an example.
Suppose we have a simple form with one field and this field is mandatory:
<%@ taglib uri="formtag.tld" prefix="html" %> <%@ taglib uri="taglib.tld" prefix="f" %> <html:form method="post" action="http://host/cgi-bin/script"> <input type=text name=username> <f:required name="username">Please, type your name</f:required> </html:form> Here tag required describes a field username as a mandatory field. Tag's body defines an error message in case of this field is empty. Also this tag lets you describe some constraint restrictions for fields (length, minimal and maximal value etc.). E.g.:
<f:required name="A" integer="true" minValue="1">field A must a positive integer</f:required> <f:required name="B" minValue="1" maxValue="10">field B is a numeric in [1 - 10] range</f:required> <!-- C is a group of radio buttons and one of them must me checked -->
<f:required name="D" dateFormat="yyyy-mm-dd">field D must be a date</f:required> Attribute selectionNotEquals is useful if you have for example some drop down box (HTML select control) with a prompt phrase (e.g. Please, select ...). You can use a value for such option as a parameter selectionNotEquals. Also you can provide for this tag a name of your own JavaScript function for validation. This function accepts current form as a parameter and must return a boolean value. You can provide a regular expression for validation. For example, this declaration tests email address:
<f:required name="email" regExp="^[\\\\w-_\\.]*[\\\\w-_\\.]\\@[\\\\w]\\.+[\\\\w]+[\\\\w]$">Please, type email address</f:required> and this expression tests US phone number (some like (800)123-4566 or 1(800) 123-4566 etc.):
<f:required name="phone" regExp="^[01]?\\\\s*[\\(\\.-]?(\\\\d{3})[\\)\\.-]?\\\\s*(\\\\d{3})[\\.-]?\\\\s*(\\\\d{4})">Please, type phone number</f:required> Tags are: required Body tag. Describes a mandatory field. Tag's body defines an error message. By default (if body is empty) tag will use message This field is mandatory. Parameters are: 1) name field's name.
for downloading: Library: checktag.jar Description: taglib.tld In order to use this taglib you have to download Form taglib also. See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in Coldtags suite:
|