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:
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.:
<!-- C is a group of radio buttons and one of them must me checked -->
<f:required name="C" checked="true"/>
<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:
and this expression tests US phone number (some like (800)123-4566 or 1(800) 123-4566 etc.):
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.
2) minLength Optional parameter. Describes a minimal length for string parameter.
Default value is 1.
3) maxLength Optional parameter. Describes a maximal length for string parameter.
4) minValue Optional parameter. Describes a minimal value for numeric parameter.
4) maxValue Optional parameter. Describes a maximal value for numeric parameter.
5) integer Optional parameter. Possible values are true or false. If this
value is true than field value must be a valid integer. Default value is false
6) numeric Optional parameter. Possible values are true or false. If this
value is true than field value must be a valid numeric. Default value is false
7) creditCard Optional parameter. Possible values are true or false. If this
value is true than field value must be a valid credit card number. Default value is false
8) dateFormat Optional parameter. Describes a format for date field. Possible values are
yyyy-mm-yy, dd/mm/yyyy etc. where yyyy presents a year, mm presents a month and dd presents a day.
If this parameter is defined than field value must be a valid date according to the given pattern.
9) selectionNotEquals Optional parameter. Describes a value to compare for lists.
10) checked Optional parameter. Possible values are true or false. If this value is true tag
assumes that this filed is a group of radio buttons or checkboxes and at least one of them must be checked. Default value is false.
11) regExp Optional parameter. Describes a regular expression for tested data.
12) customFunction Optional parameter. Describes a name for your own validation function.
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.