#include <Wt/WRegExpValidator>
Public Member Functions | |
WRegExpValidator (WObject *parent=0) | |
Sets a new regular expression validator. | |
WRegExpValidator (const WString &pattern, WObject *parent=0) | |
Sets a new regular expression validator that accepts input that matches the given regular expression. | |
~WRegExpValidator () | |
Destructor. | |
void | setRegExp (const WString &pattern) |
Sets the regular expression for valid input. | |
WString | regExp () const |
Returns the regular expression for valid input. | |
virtual State | validate (WString &input) const |
Validates the given input. | |
virtual void | createExtConfig (std::ostream &config) const |
Provides Ext-compatible config options for client-side validation. | |
void | setNoMatchText (const WString &text) |
Sets the text to be shown if no match can be found. | |
void | setInvalidNoMatchText (const WString &text) |
Sets the message to display when the input does not match. | |
WString | invalidNoMatchText () const |
Returns the message displayed when the input does not match. | |
Protected Member Functions | |
std::string | javaScriptValidate (const std::string &jsRef) const |
Creates a Javascript expression that validates the input. |
This validator checks whether user input is matched by the given (perl-like) regular expression.
The following perl features are not supported (since client-side validation cannot handle them):
Usage example:
Wt::WLineEdit *lineEdit = new Wt::WLineEdit(this); // an email address validator Wt::WRegExpValidator *validator = new Wt::WRegExpValidator("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}"); lineEdit->setValidator(validator); lineEdit->setText("koen@emweb.be");
Sets a new regular expression validator that accepts input that matches the given regular expression.
This constructs a validator that matches the perl regular expression expr
.
void Wt::WRegExpValidator::setRegExp | ( | const WString & | pattern | ) |
Sets the regular expression for valid input.
Sets the perl regular expression expr
.
WString Wt::WRegExpValidator::regExp | ( | ) | const |
Returns the regular expression for valid input.
Returns the perl regular expression.
WValidator::State Wt::WRegExpValidator::validate | ( | WString & | input | ) | const [virtual] |
Validates the given input.
The input is considered valid only when it is blank for a non-mandatory field, or matches the regular expression.
Reimplemented from Wt::WValidator.
void Wt::WRegExpValidator::setNoMatchText | ( | const WString & | text | ) |
Sets the text to be shown if no match can be found.
Sets the text to be shown if no match can be found.
void Wt::WRegExpValidator::setInvalidNoMatchText | ( | const WString & | text | ) |
Sets the message to display when the input does not match.
The default value is "Invalid input".
WString Wt::WRegExpValidator::invalidNoMatchText | ( | ) | const |
Returns the message displayed when the input does not match.
std::string Wt::WRegExpValidator::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.
Reimplemented from Wt::WValidator.