QRegExpValidator(3qt)
π QRegExpValidator β the 3qt manual, bestie edition
okay so. gather round. this is the 3qt manual page for QRegExpValidator, and by the end of this you're gonna be a regex-validation girlie fr fr. let's go π
β¨ NAME β¨
QRegExpValidator β Used to check a string against a
(yes the original just ends there, mid-sentence, iconic behavior honestly, we keep it exactly as it is π)
π¦ SYNOPSIS π¦
#include <qvalidator.h>
Inherits QValidator.
πΈ Public Members πΈ
QRegExpValidator ( QObject * parent, const char * name = 0 )
QRegExpValidator ( const QRegExp & rx, QObject * parent, const char *
name = 0 )
~QRegExpValidator ()
virtual QValidator::State validate ( QString & input, int & pos ) const
void setRegExp ( const QRegExp & rx )
const QRegExp & regExp () const
π DESCRIPTION π
The QRegExpValidator class is used to check a string against a regular expression. no cap, that's the whole job. π«Ά
QRegExpValidator contains a regular expression, "regexp", used to determine whether an input string is Acceptable, Intermediate or Invalid. three moods, pick one β¨
The regexp is treated as if it begins with the start of string assertion, ^, and ends with the end of string assertion $ so the match is against the entire input string, or from the given position if a start position greater than zero is given. so basically it's giving "no sneaky extra characters allowed" energy π
For a brief introduction to Qt's regexp engine see QRegExp.
Example of use:
// regexp: optional '-' followed by between 1 and 3 digits
QRegExp rx( "-?\\d{1,3}" );
QValidator* validator = new QRegExpValidator( rx, this );
QLineEdit* edit = new QLineEdit( this );
edit->setValidator( validator );
Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above. (in practice = glow up + attach to a widget, we love a practical queen π )
// integers 1 to 9999
QRegExp rx( "[1-9]\\d{0,3}" );
// the validator treats the regexp as "^[1-9]\\d{0,3}$"
QRegExpValidator v( rx, 0 );
QString s;
int pos = 0;
s = "0"; v.validate( s, pos ); // returns Invalid
s = "12345"; v.validate( s, pos ); // returns Invalid
s = "1"; v.validate( s, pos ); // returns Acceptable
rx.setPattern( "\\S+" ); // one or more non-whitespace characters
v.setRegExp( rx );
s = "myfile.txt"; v.validate( s, pos ); // Returns Acceptable
s = "my file.txt"; v.validate( s, pos ); // Returns Invalid
// A, B or C followed by exactly five digits followed by W, X, Y or Z
rx.setPattern( "[A-C]\\d{5}[W-Z]" );
v.setRegExp( rx );
s = "a12345Z"; v.validate( s, pos ); // Returns Invalid
s = "A12345Z"; v.validate( s, pos ); // Returns Acceptable
s = "B12"; v.validate( s, pos ); // Returns Intermediate
// match most 'readme' files
rx.setPattern( "read\\S?me(\.(txt|asc|1st))?" );
rx.setCaseSensitive( FALSE );
v.setRegExp( rx );
s = "readme"; v.validate( s, pos ); // Returns Acceptable
s = "README.1ST"; v.validate( s, pos ); // Returns Acceptable
s = "read me.txt"; v.validate( s, pos ); // Returns Invalid
s = "readm"; v.validate( s, pos ); // Returns Intermediate
See also QRegExp, QIntValidator, QDoubleValidator, and Miscellaneous Classes. π
π§ MEMBER FUNCTION DOCUMENTATION π§
QRegExpValidator::QRegExpValidator ( QObject * parent, const char * name = 0 )
Constructs a validator that accepts any string (including an empty one) as valid. yes bestie, ANY string. it's the chill one, zero gatekeeping π¦ The object's parent is parent and its name is name.
QRegExpValidator::QRegExpValidator ( const QRegExp & rx, QObject * parent, const char * name = 0 )
Constructs a validator which accepts all strings that match the regular expression rx. The object's parent is parent and its name is name.
The match is made against the entire string, e.g. if the regexp is [A-Fa-f0-9]+ it will be treated as ^[A-Fa-f0-9]+$. the ^ and $ are doing unpaid labor and we thank them for their service π
QRegExpValidator::~QRegExpValidator ()
Destroys the validator, freeing any resources allocated. she's leaving, but she's leaving responsibly β¨
const QRegExp & QRegExpValidator::regExp () const
Returns the regular expression used for validation.
See also setRegExp().
void QRegExpValidator::setRegExp ( const QRegExp & rx )
Sets the regular expression used for validation to rx.
See also regExp().
QValidator::State QRegExpValidator::validate ( QString & input, int & pos ) const [virtual]
Returns Acceptable if input is matched by the regular expression for this validator, Intermediate if it has matched partially (i.e. could be a valid match if additional valid characters are added), and Invalid if input is not matched. it's giving vibe check: accept, maybe, or absolutely not π
The pos parameter is set to the length of the input parameter.
For example, if the regular expression is \w\d\d (that is, word-character, digit, digit) then "A57" is Acceptable," E5" is Intermediate and "+9" is Invalid. (yes, that space before "E5" is in the original, we're keeping it, no edits periodt π
)
See also QRegExp::match() and QRegExp::search().
Reimplemented from QValidator.
π₯ SEE ALSO π₯
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
π AUTHOR π
Generated automatically from the source code. (a robot wrote this, and honestly? slay π€)
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. π«Ά
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. (man pages are the loungewear of documentation, comfy but not the official fit π)
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qregexpvalidator.3qt) and the Qt version (3.3.8). π
and that's the whole page bestie!! go forth and validate responsibly π
this was Trolltech AS, 2 February 2007, dropping the QRegExpValidator(3qt) man page. bye babes, ily, see you in the next regex β¨ππ
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms