Wt  3.7.1
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. More...
 
 ~WRegExpValidator ()
 Destructor.
 
void setRegExp (const WString &pattern)
 Sets the regular expression for valid input. More...
 
WString regExp () const
 Returns the regular expression for valid input. More...
 
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. More...
 
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. More...
 
void setInvalidNoMatchText (const WString &text)
 Sets the message to display when the input does not match. More...
 
WString invalidNoMatchText () const
 Returns the message displayed when the input does not match. More...
 
virtual 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.
 
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...
 
- 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 WObjectsender ()
 Returns the sender of the current slot call. More...
 

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):

See http://www.boost.org/doc/libs/release/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html for a full overview of the supported regular expression syntax. However, if you want client-side validation to work correctly, you will have to limit your regular expressions to those features supported by JavaScript (ECMAScript style regular expressions). See http://en.cppreference.com/w/cpp/regex/ecmascript for an overview of the ECMAScript regular expression syntax.

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

◆ WRegExpValidator()

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

◆ invalidNoMatchText()

WString Wt::WRegExpValidator::invalidNoMatchText ( ) const

Returns the message displayed when the input does not match.

See also
setInvalidNoMatchText(const WString&)

◆ javaScriptValidate()

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.

Reimplemented in Wt::WTimeValidator.

◆ regExp()

WString Wt::WRegExpValidator::regExp ( ) const

Returns the regular expression for valid input.

Returns the perl regular expression.

◆ setInvalidNoMatchText()

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

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

The default value is "Invalid input".

◆ setNoMatchText()

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

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

This calls setInvalidNoMatchText()

Deprecated:
Use setInvalidNoMatchText() instead

◆ setRegExp()

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

Sets the regular expression for valid input.

Sets the perl regular expression expr.

◆ validate()

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.

Reimplemented in Wt::WTimeValidator.


Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13