Validation taglib ver. 1.3

    Custom JSP taglib. Lets you validate HTML (WML) forms. Taglib contains a set of body tags each of them executes own body in case of parameter's value presents some valid data (e.g.: email address, phone number, integer value from the given interval etc.). Let we see a typical scenario:

you have some HTML form:
 


<form method="post" action="some.jsp">
  <input type="text" name="fld">
  ...
</form>

and in some.jsp you have to validate user's input. For example, text field fld must be non-empty:

 


<%@ taglib uri="taglib.tld" prefix="if" %>

<if:validString value="<%=request.getParameter(\"fld\")%>">

  <!-- do something if field is non-empty -->

</if:validString>

or some field must be a positive integer:
 


<if:notValidInteger value="<%request.getParameter(\"fld\")%>" from="1">
  <!-- incorrect value! -->
</if:notValidInteger>

see also Back tag. You may use it here:
 


<if:notValidInteger value="<%request.getParameter(\"fld\")%>" from="1">
  <go:Back alert="Please, type correct value"/>
</if:notValidInteger>

Tags are:

validString

Body tag. Executes own body if parameter presents a correct string. Parameters are:

1) value tested string
2) length Optional parameter. Describes minimal length for string. Default value is 1.

notValidString

Body tag. Executes own body if parameter does not present a correct string. Parameters are:

1) value tested string
2) length Optional parameter. Describes minimal length for string. Default value is 1.

validToken

Body tag. Executes own body if parameter presents one of given tokens. In other words tag tests value against the commas separated list of strings. Parameters are:

1) value tested string
2) tokens comma separated list of tokens
3) ignoreCase Optional parameter. Possible values are true or false. Describes how to compare strings. Default value is false

For example:

<if:validToken value="<%=s%>" tokens="yes,no">
  <!-- value is yes or no -->
</if:validToken>

notValidToken

Body tag. Executes own body if parameter is not in the list. Parameters are:

1) value tested string
2) tokens comma separated list of tokens
3) ignoreCase Optional parameter. Possible values are true or false. Describes how to compare strings. Default value is false

<if:notValidToken value="<%=s%>" tokens="yes,no" ignoreCase="true">
  <!-- nor yes, no, Yes etc. -->
</if:notValidToken>

validMoney

Body tag. Executes own body if parameter presents a float value with up to two digits after dot. Parameters are:

1) value tested value

notValidMoney

Body tag. Executes own body if parameter does not present a float value with up to two digits after dot. Parameters are:

1) value tested value

validInteger

Body tag. Executes own body if parameter presents some integer value. Parameters are:

1) value tested value
2) from Optional parameter: a minimal value
3) to Optional parameter: a maximal value

notValidInteger

Body tag. Executes own body if parameter does not present some integer value. Parameters are:

1) value tested value
2) from Optional parameter: a minimal value
3) to Optional parameter: a maximal value

validDate

Body tag. Executes own body if parameter presents some date. Date format must include dd - day, mm - month and yyyy - year Parameters are:

1) value tested value
2) format date format

notValidDate

Body tag. Executes own body if parameter does not present some date. Parameters are:

1) value tested value
2) format date format

For example:

<if:validDate value="<%=s%>" format="mm-dd-yyyy">
  <!-- Expected value is something like 11-01-2001 -->
</if:validDate>

<if:validDate value="<%=s%>" format="dd/mm/yyyy">
  <!-- Expected value is something like 11/01/2001 -->
</if:validDate>

validEmail

Body tag. Executes own body if parameter presents some e-mail address. Parameters are:

1) value tested value

notValidEmail

Body tag. Executes own body if parameter does not present some e-mail address. Parameters are:

1) value tested value

validURL

Body tag. Executes own body if parameter presents some URL. Parameters are:

1) value tested value

notValidURL

Body tag. Executes own body if parameter does not present some URL. Parameters are:

1) value tested value

validPhone

Body tag. Executes own body if parameter presents some phone number (tag understands some like 123-45-66 or +7-(095)-123-4566 etc.) Parameters are:

1) value tested value

notValidPhone

Body tag. Executes own body if parameter doesn not present some phone number (tag understands some like 123-45-66 or +7-(095) 123 4566 etc.) Parameters are:

1) value tested value

for downloading:

Library: validtag.jar    Description: taglib.tld

© Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.