Wt: Wt::WIntValidator Class Reference

Wt 3.3.0

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

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::WIntValidator Class Reference

A validator that validates integer user input. More...

`#include <Wt/WIntValidator>`

Inheritance diagram for Wt::WIntValidator:
[legend]

List of all members.

## Public Member Functions
| WIntValidator (WObject *parent=0)
| Creates a new integer validator that accepts any integer.
| WIntValidator (int minimum, int maximum, WObject *parent=0)
| Creates a new integer validator that accepts integer input within the given range.
int | bottom () const
| Returns the bottom of the valid integer range.
void | setBottom (int bottom)
| Sets the bottom of the valid integer range.
int | top () const
| Returns the top of the valid integer range.
void | setTop (int top)
| Sets the top of the valid integer range.
virtual void | setRange (int bottom, int top)
| Sets the range of valid integers.
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 | setInvalidNotANumberText (const WString &text)
| Sets the message to display when the input is not a number.
WString | invalidNotANumberText () const
| Returns the message displayed when the input is not a number.
void | setInvalidTooSmallText (const WString &text)
| Sets the message to display when the number is too small.
WString | invalidTooSmallText () const
| Returns the message displayed when the number is too small.
void | setInvalidTooLargeText (const WString &text)
| Sets the message to display when the number is too large.
WString | invalidTooLargeText () const
| Returns the message displayed when the number is too large.
virtual std::string | javaScriptValidate () const
| Creates a Javascript object that validates the input.
virtual std::string | inputFilter () const
| Returns a regular expression that filters input.

## Detailed Description

A validator that validates integer user input.

This validator checks whether user input is an integer number in a pre-defined range.

Usage example:

     Wt::WLineEdit *lineEdit = new Wt::WLineEdit(this);
     Wt::WIntValidator *validator = new Wt::WIntValidator(0, 100);
     lineEdit->setValidator(validator);
     lineEdit->setText("50");

### i18n

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

- Wt.WIntValidator.NotAnInteger: Must be an integer number
- Wt.WIntValidator.TooSmall: The number must be larger than {1}
- Wt.WIntValidator.BadRange: The number must be in the range {1} to {2}
- Wt.WIntValidator.TooLarge: The number must be smaller than {1}

## Constructor & Destructor Documentation

Wt::WIntValidator::WIntValidator | ( | WObject * | parent = `0` | ) |

Creates a new integer validator that accepts any integer.

The validator will accept numbers using the current locale's format.

See also:
  WLocale::currentLocale()

Wt::WIntValidator::WIntValidator | ( | int | minimum,
|  | int | maximum,
|  | WObject * | parent = `0`
| ) |  |

Creates a new integer validator that accepts integer input within the given range.

See also:
  WLocale::currentLocale()

## Member Function Documentation

std::string Wt::WIntValidator::inputFilter | ( |  | ) | const`[virtual]`

Returns a regular expression that filters input.

The returned regular expression is used to filter keys presses. The regular expression should accept valid single characters.

For details on valid regular expressions, see WRegExpValidator. As an example, "[0-9]" would only accept numbers as valid input.

The default implementation returns an empty string, which does not filter any input.

See also:
  javaScriptValidate()

Reimplemented from Wt::WValidator.

WString Wt::WIntValidator::invalidNotANumberText | ( |  | ) | const

Returns the message displayed when the input is not a number.

See also:
  setInvalidNotANumberText(const WString&)

WString Wt::WIntValidator::invalidTooLargeText | ( |  | ) | const

Returns the message displayed when the number is too large.

See also:
  setInvalidTooLargeText(const WString&)

WString Wt::WIntValidator::invalidTooSmallText | ( |  | ) | const

Returns the message displayed when the number is too small.

See also:
  setInvalidTooSmallText(const WString&)

std::string Wt::WIntValidator::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.

void Wt::WIntValidator::setBottom | ( | int | bottom | ) |

Sets the bottom of the valid integer range.

The default value is the minimum integer value.

void Wt::WIntValidator::setInvalidNotANumberText | ( | const WString & | text | ) |

Sets the message to display when the input is not a number.

The default value is "Must be an integer number."

void Wt::WIntValidator::setInvalidTooLargeText | ( | const WString & | text | ) |

Sets the message to display when the number is too large.

Depending on whether bottom() and top() are real bounds, the default message is "The number must be between {1} and {2}" or "The number must be smaller than {2}".

void Wt::WIntValidator::setInvalidTooSmallText | ( | const WString & | text | ) |

Sets the message to display when the number is too small.

Depending on whether bottom() and top() are real bounds, the default message is "The number must be between {1} and {2}" or "The number must be larger than {1}".

void Wt::WIntValidator::setTop | ( | int | top | ) |

Sets the top of the valid integer range.

The default value is the maximum integer value.

WValidator::Result Wt::WIntValidator::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 represents an integer within the valid range.

Reimplemented from Wt::WValidator.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator