1QRegExpValidator(3qt) QRegExpValidator(3qt)
2
3
4
6 QRegExpValidator - Used to check a string against a
7
9 #include <qvalidator.h>
10
11 Inherits QValidator.
12
13 Public Members
14 QRegExpValidator ( QObject * parent, const char * name = 0 )
15 QRegExpValidator ( const QRegExp & rx, QObject * parent, const char *
16 name = 0 )
17 ~QRegExpValidator ()
18 virtual QValidator::State validate ( QString & input, int & pos ) const
19 void setRegExp ( const QRegExp & rx )
20 const QRegExp & regExp () const
21
23 The QRegExpValidator class is used to check a string against a regular
24 expression.
25
26 QRegExpValidator contains a regular expression, "regexp", used to
27 determine whether an input string is Acceptable, Intermediate or
28 Invalid.
29
30 The regexp is treated as if it begins with the start of string
31 assertion, ^, and ends with the end of string assertion $ so the match
32 is against the entire input string, or from the given position if a
33 start position greater than zero is given.
34
35 For a brief introduction to Qt's regexp engine see QRegExp.
36
37 Example of use:
38
39 // regexp: optional '-' followed by between 1 and 3 digits
40 QRegExp rx( "-?\\d{1,3}" );
41 QValidator* validator = new QRegExpValidator( rx, this );
42 QLineEdit* edit = new QLineEdit( this );
43 edit->setValidator( validator );
44
45 Below we present some examples of validators. In practice they would
46 normally be associated with a widget as in the example above.
47
48 // integers 1 to 9999
49 QRegExp rx( "[1-9]\\d{0,3}" );
50 // the validator treats the regexp as "^[1-9]\\d{0,3}$"
51 QRegExpValidator v( rx, 0 );
52 QString s;
53 int pos = 0;
54 s = "0"; v.validate( s, pos ); // returns Invalid
55 s = "12345"; v.validate( s, pos ); // returns Invalid
56 s = "1"; v.validate( s, pos ); // returns Acceptable
57 rx.setPattern( "\\S+" ); // one or more non-whitespace characters
58 v.setRegExp( rx );
59 s = "myfile.txt"; v.validate( s, pos ); // Returns Acceptable
60 s = "my file.txt"; v.validate( s, pos ); // Returns Invalid
61 // A, B or C followed by exactly five digits followed by W, X, Y or Z
62 rx.setPattern( "[A-C]\\d{5}[W-Z]" );
63 v.setRegExp( rx );
64 s = "a12345Z"; v.validate( s, pos ); // Returns Invalid
65 s = "A12345Z"; v.validate( s, pos ); // Returns Acceptable
66 s = "B12"; v.validate( s, pos ); // Returns Intermediate
67 // match most 'readme' files
68 rx.setPattern( "read\\S?me(\.(txt|asc|1st))?" );
69 rx.setCaseSensitive( FALSE );
70 v.setRegExp( rx );
71 s = "readme"; v.validate( s, pos ); // Returns Acceptable
72 s = "README.1ST"; v.validate( s, pos ); // Returns Acceptable
73 s = "read me.txt"; v.validate( s, pos ); // Returns Invalid
74 s = "readm"; v.validate( s, pos ); // Returns Intermediate
75
76 See also QRegExp, QIntValidator, QDoubleValidator, and Miscellaneous
77 Classes.
78
81
82 Constructs a validator that accepts any string (including an empty one)
83 as valid. The object's parent is parent and its name is name.
84
86 const char * name = 0 )
87 Constructs a validator which accepts all strings that match the regular
88 expression rx. The object's parent is parent and its name is name.
89
90 The match is made against the entire string, e.g. if the regexp is [A-
91 Fa-f0-9]+ it will be treated as ^[A-Fa-f0-9]+$.
92
94 Destroys the validator, freeing any resources allocated.
95
97 Returns the regular expression used for validation.
98
99 See also setRegExp().
100
102 Sets the regular expression used for validation to rx.
103
104 See also regExp().
105
107 const [virtual]
108 Returns Acceptable if input is matched by the regular expression for
109 this validator, Intermediate if it has matched partially (i.e. could be
110 a valid match if additional valid characters are added), and Invalid if
111 input is not matched.
112
113 The pos parameter is set to the length of the input parameter.
114
115 For example, if the regular expression is \w\d\d (that is,
116 word-character, digit, digit) then "A57" is Acceptable," E5" is
117 Intermediate and "+9" is Invalid.
118
119 See also QRegExp::match() and QRegExp::search().
120
121 Reimplemented from QValidator.
122
123
125 http://doc.trolltech.com/qregexpvalidator.html
126 http://www.trolltech.com/faq/tech.html
127
129 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
130 license file included in the distribution for a complete license
131 statement.
132
134 Generated automatically from the source code.
135
137 If you find a bug in Qt, please report it as described in
138 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
139 help you. Thank you.
140
141 The definitive Qt documentation is provided in HTML format; it is
142 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
143 web browser. This man page is provided as a convenience for those users
144 who prefer man pages, although this format is not officially supported
145 by Trolltech.
146
147 If you find errors in this manual page, please report them to qt-
148 bugs@trolltech.com. Please include the name of the manual page
149 (qregexpvalidator.3qt) and the Qt version (3.3.8).
150
151
152
153Trolltech AS 2 February 2007 QRegExpValidator(3qt)