Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wordsmithing

...

Validator

Constraint Type

Description

Example

email

Ensures that the given input looks like a valid e-mail address

<t:textfield value="emailuserEmail" validate="email" />

max

long

Enforces a maximum integer value

<t:textfield value="age" validate="max=120,min=0" />

maxLength

int

Makes sure that a string value has a maximum length

<t:textfield value="zip" validate="maxlength=7" />

min

long

Enforces a minimum integer value

<t:textfield value="age" validate="max=120,min=0" />

minLength

int

Makes sure that a string value has a minimum length

<t:textfield value="somefield" validate="minlength=1" />

none

Does nothing (used to override a @Validate annotation)

<t:textfield value="somefield" validate="none" />

regexp

pattern

Makes sure that a string value conforms to a given pattern

<t:textfield value="letterfield" validate="regexp=^[A-Za-z]+$" />

required

Makes sure that a string value is not null and not the empty string

<t:textfield value="name" validate="required" />

...

HTML5 Client-side Validation

When the "the tapestry.enable-html5-support" symbol is set to true (it is false by default), the Tapestry's built-in validators will automatically add enable the appropriate HTML5-specific "type" and validation attributes to the rendered HTML of Tapestry's form components, triggering the HTML5 client-side validation behavior built into most modern browsers. For example, if you use the "email" validatorand "required" validators, like this:

Code Block
<t:textfield value="user.emailAddress" validate="email,required" />

then the output HTML will look like this:

Code Block
<input type="email" required ...>

which causes modern browsers to present a validation error message whenever text is entered that doesn't look like an email address, or if the field is left blank.

The browser's built-in validation is performed before Tapestry's own client-side validation. This is so that older browsers will still perform client-side validation as expected.

The following behaviors are includedThe following HTML5 validation behaviors are enabled:

  • The "required" validator adds the "required" attribute to the rendered HTML
  • The "regexp" validator adds the "pattern" attribute to the rendered HTML
  • The "email" validator sets the type attribute to "email" in the rendered HTML
  • The "min" validator sets the type attribute to "number" and adds the "min" attribute in the rendered HTML
  • The "max" validator sets the type attribute to "number" and adds the "max" attribute in the rendered HTML
  • When bound to a number type, the TextField component sets the type attribute to "number" in the rendered HTML

...