Wt
3.3.8
|
A validator that checks the string length of user input. More...
#include <Wt/WLengthValidator>
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. More... | |
int | minimumLength () const |
Returns the minimum length. More... | |
void | setMaximumLength (int maximum) |
Sets the maximum length. More... | |
int | maximumLength () const |
Returns the maximum length. More... | |
virtual Result | validate (const WString &input) const |
Validates the given input. More... | |
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. More... | |
WString | invalidTooShortText () const |
Returns the message displayed when the input is too short. More... | |
void | setInvalidTooLongText (const WString &text) |
Sets the message to display when the input is too long. More... | |
WString | invalidTooLongText () const |
Returns the message displayed when the input is too long. More... | |
std::string | javaScriptValidate () const |
Creates a Javascript object that validates the input. More... | |
Public Member Functions inherited from Wt::WValidator | |
WValidator (WObject *parent=0) | |
Creates a new validator. | |
WValidator (bool mandatory, WObject *parent=0) | |
Creates a new validator. More... | |
~WValidator () | |
Destructor. More... | |
void | setMandatory (bool how) |
Sets if input is mandatory. More... | |
bool | isMandatory () const |
Returns if input is mandatory. | |
void | setInvalidBlankText (const WString &text) |
Sets the message to display when a mandatory field is left blank. More... | |
WString | invalidBlankText () const |
Returns the message displayed when a mandatory field is left blank. More... | |
virtual WString | format () const |
Returns the validator format. More... | |
virtual std::string | inputFilter () const |
Returns a regular expression that filters input. More... | |
Public Member Functions inherited from Wt::WObject | |
WObject (WObject *parent=0) | |
Create a WObject with a given parent object. More... | |
virtual | ~WObject () |
Destructor. More... | |
virtual const std::string | id () const |
Returns the (unique) identifier for this object. More... | |
virtual void | setObjectName (const std::string &name) |
Sets an object name. More... | |
virtual std::string | objectName () const |
Returns the object name. More... | |
void | resetLearnedSlots () |
Resets learned stateless slot implementations. More... | |
template<class T > | |
void | resetLearnedSlot (void(T::*method)()) |
Resets a learned stateless slot implementation. More... | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)()) |
Declares a slot to be stateless and learn client-side behaviour on first invocation. More... | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
Declares a slot to be stateless and learn client-side behaviour in advance. More... | |
void | isNotStateless () |
Marks the current function as not stateless. More... | |
template<class T > | |
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
Provides a JavaScript implementation for a method. More... | |
void | addChild (WObject *child) |
Adds a child object. More... | |
virtual void | removeChild (WObject *child) |
Removes a child object. More... | |
const std::vector< WObject * > & | children () const |
Returns the children. | |
WObject * | parent () const |
Returns the parent object. | |
Additional Inherited Members | |
Public Types inherited from Wt::WValidator | |
Public Types inherited from Wt::WObject | |
typedef void(WObject::* | Method) () |
Typedef for a WObject method without arguments. | |
Protected Member Functions inherited from Wt::WObject | |
virtual WStatelessSlot * | getStateless (Method method) |
On-demand stateless slot implementation. More... | |
Static Protected Member Functions inherited from Wt::WObject | |
static WObject * | sender () |
Returns the sender of the current slot call. More... | |
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:
The strings used in this class can be translated by overriding the default values for the following localization keys:
WString Wt::WLengthValidator::invalidTooLongText | ( | ) | const |
Returns the message displayed when the input is too long.
WString Wt::WLengthValidator::invalidTooShortText | ( | ) | const |
Returns the message displayed when the input is too short.
|
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:
message
that indicates the problem if not valid.Returns an empty string if the validator does not provide a client-side validation implementationq.
Reimplemented from Wt::WValidator.
int Wt::WLengthValidator::maximumLength | ( | ) | const |
Returns the maximum length.
int Wt::WLengthValidator::minimumLength | ( | ) | const |
Returns the minimum length.
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.
|
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.