summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqregexpvalidator.3qt
blob: 4f620be65bd4886b03675e8e6c599e33f62885e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'\" t
.TH TQRegExpValidator 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
TQRegExpValidator \- Used to check a string against a
.SH SYNOPSIS
\fC#include <tqvalidator.h>\fR
.PP
Inherits TQValidator.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQRegExpValidator\fR ( TQObject * parent, const char * name = 0 )"
.br
.ti -1c
.BI "\fBTQRegExpValidator\fR ( const TQRegExp & rx, TQObject * parent, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~TQRegExpValidator\fR ()"
.br
.ti -1c
.BI "virtual TQValidator::State \fBvalidate\fR ( TQString & input, int & pos ) const"
.br
.ti -1c
.BI "void \fBsetRegExp\fR ( const TQRegExp & rx )"
.br
.ti -1c
.BI "const TQRegExp & \fBregExp\fR () const"
.br
.in -1c
.SH DESCRIPTION
The TQRegExpValidator class is used to check a string against a regular expression.
.PP
TQRegExpValidator 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 TQRegExp.
.PP
Example of use:
.PP
.nf
.br
    // regexp: optional '-' followed by between 1 and 3 digits
.br
    TQRegExp rx( "-?\\\\d{1,3}" );
.br
    TQValidator* validator = new TQRegExpValidator( rx, this );
.br
.br
    TQLineEdit* edit = new TQLineEdit( 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
    TQRegExp rx( "[1-9]\\\\d{0,3}" );
.br
    // the validator treats the regexp as "^[1-9]\\\\d{0,3}$"
.br
    TQRegExpValidator v( rx, 0 );
.br
    TQString 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
.br
.br
    // match most 'readme' files
.br
    rx.setPattern( "read\\\\S?me(\\.(txt|asc|1st))?" );
.br
    rx.setCaseSensitive( FALSE );
.br
    v.setRegExp( rx );
.br
    s = "readme";      v.validate( s, pos ); // Returns Acceptable
.br
    s = "README.1ST";  v.validate( s, pos ); // Returns Acceptable
.br
    s = "read me.txt"; v.validate( s, pos ); // Returns Invalid
.br
    s = "readm";       v.validate( s, pos ); // Returns Intermediate
.br
.fi
.PP
See also TQRegExp, TQIntValidator, TQDoubleValidator, and Miscellaneous Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQRegExpValidator::TQRegExpValidator ( TQObject * parent, const char * name = 0 )"
Constructs a validator that accepts any string (including an empty one) as valid. The object's parent is \fIparent\fR and its name is \fIname\fR.
.SH "TQRegExpValidator::TQRegExpValidator ( const TQRegExp & rx, TQObject * parent, const char * name = 0 )"
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 "TQRegExpValidator::~TQRegExpValidator ()"
Destroys the validator, freeing any resources allocated.
.SH "const TQRegExp & TQRegExpValidator::regExp () const"
Returns the regular expression used for validation.
.PP
See also setRegExp().
.SH "void TQRegExpValidator::setRegExp ( const TQRegExp & rx )"
Sets the regular expression used for validation to \fIrx\fR.
.PP
See also regExp().
.SH "TQValidator::State TQRegExpValidator::validate ( TQString & input, int & pos ) const\fC [virtual]\fR"
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&#92;w&#92;d&#92;d\fR (that is, word-character, digit, digit) then "A57" is Acceptable," E5" is Intermediate and "+9" is Invalid.
.PP
See also TQRegExp::match() and TQRegExp::search().
.PP
Reimplemented from TQValidator.

.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqregexpvalidator.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt 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. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqregexpvalidator.3qt) and the Qt
version (3.3.8).