#include <WValidator>
Public Types | |
enum | State { Invalid, InvalidEmpty, Valid } |
The state in which validated input can exist. More... | |
Public Member Functions | |
WValidator (bool mandatory=false) | |
Create a new validator. | |
void | setMandatory (bool how) |
Set if input is mandatory. | |
bool | isMandatory () const |
Returns if input is mandatory. | |
void | setInvalidBlankText (const WString &text) |
Set message to display when a mandatory field is left blank. | |
virtual void | fixup (WString &input) const |
This function attempts to change input to be valid according to the validator's rules. | |
virtual State | validate (WString &input, int &pos) const |
Evaluate the validness of the given input. | |
virtual void | createExtConfig (std::ostream &config) const |
Provide Ext-compatible config options for client-side validation. |
A WValidator can be associated with a WFormWidget, using WFormWidget::setValidator.
This WValidator only checks that mandatory fields are not empty. This class is reimplemented in WIntValidator, WDoubleValidator, and WRegExpValidator, which perform checks on the input as well.
If these validators are not suitable, you can inherit from this class, and provide a suitable implementation to validate() and fixup().
A validator may have a split implementation to provide both validation at the client-side (and give instant feed-back to the user editing), and server-side validation (to be sure that the client was not tampered with).
Wt::WValidator::WValidator | ( | bool | mandatory = false |
) |
void Wt::WValidator::setMandatory | ( | bool | how | ) |
Set if input is mandatory.
When an input is not mandatory, then an empty field is always valid.
void Wt::WValidator::fixup | ( | WString & | input | ) | const [virtual] |
This function attempts to change input to be valid according to the validator's rules.
In general the function needs not to change the input into a valid input. The default implementation does nothing. But it may help the user in getting its input right.
WValidator::State Wt::WValidator::validate | ( | WString & | input, | |
int & | pos | |||
) | const [virtual] |
Evaluate the validness of the given input.
This function returns the current state of the input.
The function can change both input and pos (the cursor position) if required.
Reimplemented in Wt::WDateValidator, Wt::WDoubleValidator, Wt::WIntValidator, Wt::WLengthValidator, and Wt::WRegExpValidator.