Wt::WLengthValidator Class Reference

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

#include <Wt/WLengthValidator>

Inheritance diagram for Wt::WLengthValidator:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 WLengthValidator (WObject *parent=0)
 Create a length validator that accepts input of any length.
 WLengthValidator (int minLength, int maxLength, WObject *parent=0)
 Create a length validator that accepts input within a length range.
void setMinimumLength (int minimum)
 Set the minimum length.
int minimumLength () const
 Return the minimum length.
void setMaximumLength (int maximum)
 Set the maximum length.
int maximumLength () const
 Returns the maximum length.
virtual State validate (WString &input, int &pos) const
 Validate the given input.
virtual void createExtConfig (std::ostream &config) const
 Provide Ext-compatible config options for client-side validation.
void setInvalidTooShortText (const WString &text)
 Set 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)
 Set message to display when the input is too long.
WString invalidTooLongText () const
 Returns the message displayed when the input is too long.

Protected Member Functions

std::string javaScriptValidate (const std::string &jsRef) const
 Creates a Javascript expression 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().


Member Function Documentation

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

Set the minimum length.

The default value is 0.

int Wt::WLengthValidator::minimumLength (  )  const [inline]

Return the minimum length.

See also:
setMinimumLength(int)

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

Set the maximum length.

The default value is std::numeric_limits<int>::max()

int Wt::WLengthValidator::maximumLength (  )  const [inline]

Returns the maximum length.

See also:
setMaximumLength(int)

WValidator::State Wt::WLengthValidator::validate ( WString input,
int &  pos 
) const [virtual]

Validate 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.

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

Set 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".

WString Wt::WLengthValidator::invalidTooShortText (  )  const

Returns the message displayed when the input is too short.

See also:
setInvalidTooShortText(const WString&)

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

Set 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".

WString Wt::WLengthValidator::invalidTooLongText (  )  const

Returns the message displayed when the input is too long.

See also:
setInvalidTooLongText(const WString&)

std::string Wt::WLengthValidator::javaScriptValidate ( const std::string &  jsRef  )  const [protected, virtual]

Creates a Javascript expression that validates the input.

The JavaScript expression should evaluate to an object with two fields: a boolean valid, and a message that indicates the problem if not valid.

Return an empty string if you are not provide the client-side validation.

See also:
inputFilter()

Reimplemented from Wt::WValidator.


Generated on Mon Jan 26 14:14:08 2009 for Wt by doxygen 1.5.6