Wt  3.3.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions | List of all members
Wt::WRegExpValidator Class Reference

A validator that checks user input against a regular expression. More...

#include <Wt/WRegExpValidator>

Inheritance diagram for Wt::WRegExpValidator:
Inheritance graph
[legend]

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.
void setFlags (WFlags< RegExpFlag > flags)
 Sets regular expression matching flags.
WFlags< RegExpFlagflags () const
 Returns regular expression matching flags.
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 setNoMatchText (const WString &text)
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.
virtual std::string javaScriptValidate () const
 Creates a Javascript object that validates the input.
- 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.
 ~WValidator ()
 Destructor.
void setMandatory (bool how)
 Sets if input is mandatory.
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.
WString invalidBlankText () const
 Returns the message displayed 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 WString format () const
 Returns the validator format.
virtual std::string inputFilter () const
 Returns a regular expression that filters input.
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 Create a WObject with a given parent object.
virtual ~WObject ()
 Destructor.
virtual const std::string id () const
 Returns the (unique) identifier for this object.
void setObjectName (const std::string &name)
 Sets an object name.
virtual std::string objectName () const
 Returns the object name.
void resetLearnedSlots ()
 Resets learned stateless slot implementations.
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance.
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
void addChild (WObject *child)
 Adds a child object.
virtual void removeChild (WObject *child)
 Removes a child object.
const std::vector< WObject * > & children () const
 Returns the children.
WObjectparent () const
 Returns the parent object.

Additional Inherited Members

- Public Types inherited from Wt::WValidator
enum  State { Invalid, InvalidEmpty, Valid }
 The state in which validated input can exist. More...
- Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation.
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()
 Returns the sender of the current slot call.

Detailed Description

A validator that checks user input against a regular expression.

This validator checks whether user input matches the given (perl-like) regular expression. It checks the complete input; prefix ^ and suffix $ are not needed.

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");
Note
This validator does not fully support unicode: it matches on the UTF8-encoded representation of the string.

i18n

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

Constructor & Destructor Documentation

Wt::WRegExpValidator::WRegExpValidator ( const WString pattern,
WObject parent = 0 
)

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.

Member Function Documentation

WString Wt::WRegExpValidator::invalidNoMatchText ( ) const

Returns the message displayed when the input does not match.

See Also
setInvalidNoMatchText(const WString&)
std::string Wt::WRegExpValidator::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.

WString Wt::WRegExpValidator::regExp ( ) const

Returns the regular expression for valid input.

Returns the perl regular expression.

void Wt::WRegExpValidator::setInvalidNoMatchText ( const WString text)

Sets the message to display when the input does not match.

The default value is "Invalid input".

void Wt::WRegExpValidator::setNoMatchText ( const WString text)

Sets the text to be shown if no match can be found.

void Wt::WRegExpValidator::setRegExp ( const WString pattern)

Sets the regular expression for valid input.

Sets the perl regular expression expr.

WValidator::Result Wt::WRegExpValidator::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 matches the regular expression.

Reimplemented from Wt::WValidator.


Generated on Thu May 30 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2