Wt: Wt::WLengthValidator Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::WLengthValidator Class Reference

A validator that checks the string length of user input. More...

`#include <Wt/WLengthValidator>`

Inheritance diagram for Wt::WLengthValidator:
[legend]

List of all members.

## Public Member Functions
| WLengthValidator (WObject *parent=0)
| Creates a length validator that accepts input of any length.
| WLengthValidator (int minLength, int maxLength, WObject *parent=0)
| Creates a length validator that accepts input within a length range.
void | setMinimumLength (int minimum)
| Sets the minimum length.
int | minimumLength () const
| Returns the minimum length.
void | setMaximumLength (int maximum)
| Sets the maximum length.
int | maximumLength () const
| Returns the maximum length.
virtual Result | validate (const WString &input) const
| Validates the given input.
virtual void | createExtConfig (std::ostream &config) const
| Provides Ext-compatible config options for client-side validation.
void | setInvalidTooShortText (const WString &text)
| Sets the message to display when the input is too short.
WString | invalidTooShortText () const
| Returns the message displayed when the input is too short.
void | setInvalidTooLongText (const WString &text)
| Sets the message to display when the input is too long.
WString | invalidTooLongText () const
| Returns the message displayed when the input is too long.
std::string | javaScriptValidate () const
| Creates a Javascript object that validates the input.

## Detailed Description

A validator that checks the string length of user input.

This validator checks whether user input is within the specified range of accepted string lengths.

If you only want to limit the length on a line edit, you may also use WLineEdit::setMaxLength().

Usage example:

     Wt::WLineEdit *lineEdit = new Wt::WLineEdit(this);
     Wt::WLengthValidator *validator = new Wt::WLengthValidator(5, 15);
     lineEdit->setValidator(validator);
     lineEdit->setText("abcdef");

### i18n

The strings used in this class can be translated by overriding the default values for the following localization keys:

- Wt.WLengthValidator.TooShort: The input must be at least {1} characters
- Wt.WLengthValidator.BadRange: The input must have a length between {1} and {2} characters
- Wt.WLengthValidator.TooLong: The input must be no more than {1} characters

## Member Function Documentation

WString Wt::WLengthValidator::invalidTooLongText | ( |  | ) | const

Returns the message displayed when the input is too long.

See also:
  setInvalidTooLongText(const WString&)

WString Wt::WLengthValidator::invalidTooShortText | ( |  | ) | const

Returns the message displayed when the input is too short.

See also:
  setInvalidTooShortText(const WString&)

std::string Wt::WLengthValidator::javaScriptValidate | ( |  | ) | const`[virtual]`

Creates a Javascript object that validates the input.

The JavaScript expression should evaluate to an object which contains a `validate(text)` function, which returns an object that contains the following two fields:

- fields: a boolean valid,
- a `message` that indicates the problem if not valid.

Returns an empty string if the validator does not provide a client-side validation implementationq.

Note:
  The signature and contract changed changed in Wt 3.1.9.

See also:
  inputFilter()

Reimplemented from Wt::WValidator.

int Wt::WLengthValidator::maximumLength | ( |  | ) | const

Returns the maximum length.

See also:
  setMaximumLength(int)

int Wt::WLengthValidator::minimumLength | ( |  | ) | const

Returns the minimum length.

See also:
  setMinimumLength(int)

void Wt::WLengthValidator::setInvalidTooLongText | ( | const WString & | text | ) |

Sets the message to display when the input is too long.

Depending on whether minimumLength() is different from zero, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be no more than {2} characters".

void Wt::WLengthValidator::setInvalidTooShortText | ( | const WString & | text | ) |

Sets the message to display when the input is too short.

Depending on whether maximumLength() is a real bound, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be at least {1} characters".

void Wt::WLengthValidator::setMaximumLength | ( | int | maximum | ) |

Sets the maximum length.

The default value is the maximum integer value.

void Wt::WLengthValidator::setMinimumLength | ( | int | minimum | ) |

Sets the minimum length.

The default value is 0.

WValidator::Result Wt::WLengthValidator::validate | ( | const WString & | input | ) | const`[virtual]`

Validates the given input.

The input is considered valid only when it is blank for a non-mandatory field, or has a length within the valid range.

Reimplemented from Wt::WValidator.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator