The QRegExpValidator class is used to check a string against a regular expression.
.PP
QRegExpValidator contains a regular expression, "regexp", used to determine whether an input string is Acceptable, Intermediate or Invalid.
.PP
The regexp is treated as if it begins with the start of string assertion, \fB^\fR, and ends with the end of string assertion \fB$\fR so the match is against the entire input string, or from the given position if a start position greater than zero is given.
.PP
For a brief introduction to Qt's regexp engine see QRegExp.
.PP
Example of use:
.PP
.nf
.br
// regexp: optional '-' followed by between 1 and 3 digits
.br
QRegExp rx( "-?\\\\d{1,3}" );
.br
QValidator* validator = new QRegExpValidator( rx, this );
.br
.br
QLineEdit* edit = new QLineEdit( this );
.br
edit->setValidator( validator );
.br
.fi
.PP
Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above.
.PP
.nf
.br
// integers 1 to 9999
.br
QRegExp rx( "[1-9]\\\\d{0,3}" );
.br
// the validator treats the regexp as "^[1-9]\\\\d{0,3}$"
.br
QRegExpValidator v( rx, 0 );
.br
QString s;
.br
int pos = 0;
.br
.br
s = "0"; v.validate( s, pos ); // returns Invalid
.br
s = "12345"; v.validate( s, pos ); // returns Invalid
.br
s = "1"; v.validate( s, pos ); // returns Acceptable
.br
.br
rx.setPattern( "\\\\S+" ); // one or more non-whitespace characters
.br
v.setRegExp( rx );
.br
s = "myfile.txt"; v.validate( s, pos ); // Returns Acceptable
.br
s = "my file.txt"; v.validate( s, pos ); // Returns Invalid
.br
.br
// A, B or C followed by exactly five digits followed by W, X, Y or Z
.br
rx.setPattern( "[A-C]\\\\d{5}[W-Z]" );
.br
v.setRegExp( rx );
.br
s = "a12345Z"; v.validate( s, pos ); // Returns Invalid
.br
s = "A12345Z"; v.validate( s, pos ); // Returns Acceptable
.br
s = "B12"; v.validate( s, pos ); // Returns Intermediate
Constructs a validator which accepts all strings that match the regular expression \fIrx\fR. The object's parent is \fIparent\fR and its name is \fIname\fR.
.PP
The match is made against the entire string, e.g. if the regexp is \fB[A-Fa-f0-9]+\fR it will be treated as \fB^[A-Fa-f0-9]+$\fR.
.SH "QRegExpValidator::~QRegExpValidator ()"
Destroys the validator, freeing any resources allocated.
Returns Acceptable if \fIinput\fR 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 \fIinput\fR is not matched.
.PP
The \fIpos\fR parameter is set to the length of the \fIinput\fR parameter.
.PP
For example, if the regular expression is \fB\w\d\d\fR (that is, word-character, digit, digit) then "A57" is Acceptable," E5" is Intermediate and "+9" is Invalid.