1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/widgets/qvalidator.cpp:517 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QRegExpValidator Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QRegExpValidator Class Reference</h1>
|
---|
33 |
|
---|
34 | <p>The QRegExpValidator class is used to check a string
|
---|
35 | against a regular expression.
|
---|
36 | <a href="#details">More...</a>
|
---|
37 | <p><tt>#include <<a href="qvalidator-h.html">qvalidator.h</a>></tt>
|
---|
38 | <p>Inherits <a href="qvalidator.html">QValidator</a>.
|
---|
39 | <p><a href="qregexpvalidator-members.html">List of all member functions.</a>
|
---|
40 | <h2>Public Members</h2>
|
---|
41 | <ul>
|
---|
42 | <li class=fn><a href="#QRegExpValidator"><b>QRegExpValidator</b></a> ( QObject * parent, const char * name = 0 )</li>
|
---|
43 | <li class=fn><a href="#QRegExpValidator-2"><b>QRegExpValidator</b></a> ( const QRegExp & rx, QObject * parent, const char * name = 0 )</li>
|
---|
44 | <li class=fn><a href="#~QRegExpValidator"><b>~QRegExpValidator</b></a> ()</li>
|
---|
45 | <li class=fn>virtual QValidator::State <a href="#validate"><b>validate</b></a> ( QString & input, int & pos ) const</li>
|
---|
46 | <li class=fn>void <a href="#setRegExp"><b>setRegExp</b></a> ( const QRegExp & rx )</li>
|
---|
47 | <li class=fn>const QRegExp & <a href="#regExp"><b>regExp</b></a> () const</li>
|
---|
48 | </ul>
|
---|
49 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
50 |
|
---|
51 |
|
---|
52 | The QRegExpValidator class is used to check a string
|
---|
53 | against a <a href="qregexp.html#regular-expression">regular expression</a>.
|
---|
54 | <p>
|
---|
55 | <p> QRegExpValidator contains a regular expression, "regexp", used to
|
---|
56 | determine whether an input string is <a href="qvalidator.html#State-enum">Acceptable</a>, <a href="qvalidator.html#State-enum">Intermediate</a> or <a href="qvalidator.html#State-enum">Invalid</a>.
|
---|
57 | <p> The regexp is treated as if it begins with the start of string
|
---|
58 | assertion, <b>^</b>, and ends with the end of string assertion
|
---|
59 | <b>$</b> so the match is against the entire input string, or from
|
---|
60 | the given position if a start position greater than zero is given.
|
---|
61 | <p> For a brief introduction to Qt's regexp engine see <a href="qregexp.html">QRegExp</a>.
|
---|
62 | <p> Example of use:
|
---|
63 | <pre>
|
---|
64 | // regexp: optional '-' followed by between 1 and 3 digits
|
---|
65 | <a href="qregexp.html">QRegExp</a> rx( "-?\\d{1,3}" );
|
---|
66 | <a href="qvalidator.html">QValidator</a>* validator = new QRegExpValidator( rx, this );
|
---|
67 |
|
---|
68 | <a href="qlineedit.html">QLineEdit</a>* edit = new <a href="qlineedit.html">QLineEdit</a>( this );
|
---|
69 | edit-><a href="qlineedit.html#setValidator">setValidator</a>( validator );
|
---|
70 | </pre>
|
---|
71 |
|
---|
72 | <p> Below we present some examples of validators. In practice they would
|
---|
73 | normally be associated with a widget as in the example above.
|
---|
74 | <p> <pre>
|
---|
75 | // integers 1 to 9999
|
---|
76 | <a href="qregexp.html">QRegExp</a> rx( "[1-9]\\d{0,3}" );
|
---|
77 | // the validator treats the regexp as "^[1-9]\\d{0,3}$"
|
---|
78 | QRegExpValidator v( rx, 0 );
|
---|
79 | <a href="qstring.html">QString</a> s;
|
---|
80 | int pos = 0;
|
---|
81 |
|
---|
82 | s = "0"; v.<a href="#validate">validate</a>( s, pos ); // returns Invalid
|
---|
83 | s = "12345"; v.<a href="#validate">validate</a>( s, pos ); // returns Invalid
|
---|
84 | s = "1"; v.<a href="#validate">validate</a>( s, pos ); // returns Acceptable
|
---|
85 |
|
---|
86 | rx.<a href="qregexp.html#setPattern">setPattern</a>( "\\S+" ); // one or more non-whitespace characters
|
---|
87 | v.<a href="#setRegExp">setRegExp</a>( rx );
|
---|
88 | s = "myfile.txt"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
---|
89 | s = "my file.txt"; v.<a href="#validate">validate</a>( s, pos ); // Returns Invalid
|
---|
90 |
|
---|
91 | // A, B or C followed by exactly five digits followed by W, X, Y or Z
|
---|
92 | rx.<a href="qregexp.html#setPattern">setPattern</a>( "[A-C]\\d{5}[W-Z]" );
|
---|
93 | v.<a href="#setRegExp">setRegExp</a>( rx );
|
---|
94 | s = "a12345Z"; v.<a href="#validate">validate</a>( s, pos ); // Returns Invalid
|
---|
95 | s = "A12345Z"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
---|
96 | s = "B12"; v.<a href="#validate">validate</a>( s, pos ); // Returns Intermediate
|
---|
97 |
|
---|
98 | // match most 'readme' files
|
---|
99 | rx.<a href="qregexp.html#setPattern">setPattern</a>( "read\\S?me(\.(txt|asc|1st))?" );
|
---|
100 | rx.<a href="qregexp.html#setCaseSensitive">setCaseSensitive</a>( FALSE );
|
---|
101 | v.<a href="#setRegExp">setRegExp</a>( rx );
|
---|
102 | s = "readme"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
---|
103 | s = "README.1ST"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
---|
104 | s = "read me.txt"; v.<a href="#validate">validate</a>( s, pos ); // Returns Invalid
|
---|
105 | s = "readm"; v.<a href="#validate">validate</a>( s, pos ); // Returns Intermediate
|
---|
106 | </pre>
|
---|
107 |
|
---|
108 | <p> <p>See also <a href="qregexp.html">QRegExp</a>, <a href="qintvalidator.html">QIntValidator</a>, <a href="qdoublevalidator.html">QDoubleValidator</a>, and <a href="misc.html">Miscellaneous Classes</a>.
|
---|
109 |
|
---|
110 | <hr><h2>Member Function Documentation</h2>
|
---|
111 | <h3 class=fn><a name="QRegExpValidator"></a>QRegExpValidator::QRegExpValidator ( <a href="qobject.html">QObject</a> * parent, const char * name = 0 )
|
---|
112 | </h3>
|
---|
113 | Constructs a validator that accepts any string (including an empty
|
---|
114 | one) as valid. The object's parent is <em>parent</em> and its name is <em>name</em>.
|
---|
115 |
|
---|
116 | <h3 class=fn><a name="QRegExpValidator-2"></a>QRegExpValidator::QRegExpValidator ( const <a href="qregexp.html">QRegExp</a> & rx, <a href="qobject.html">QObject</a> * parent, const char * name = 0 )
|
---|
117 | </h3>
|
---|
118 | Constructs a validator which accepts all strings that match the
|
---|
119 | <a href="qregexp.html#regular-expression">regular expression</a> <em>rx</em>. The object's parent is <em>parent</em> and its
|
---|
120 | name is <em>name</em>.
|
---|
121 | <p> The match is made against the entire string, e.g. if the regexp is
|
---|
122 | <b>[A-Fa-f0-9]+</b> it will be treated as <b>^[A-Fa-f0-9]+$</b>.
|
---|
123 |
|
---|
124 | <h3 class=fn><a name="~QRegExpValidator"></a>QRegExpValidator::~QRegExpValidator ()
|
---|
125 | </h3>
|
---|
126 | Destroys the validator, freeing any resources allocated.
|
---|
127 |
|
---|
128 | <h3 class=fn>const <a href="qregexp.html">QRegExp</a> & <a name="regExp"></a>QRegExpValidator::regExp () const
|
---|
129 | </h3>
|
---|
130 |
|
---|
131 | <p> Returns the <a href="qregexp.html#regular-expression">regular expression</a> used for validation.
|
---|
132 | <p> <p>See also <a href="#setRegExp">setRegExp</a>().
|
---|
133 |
|
---|
134 | <h3 class=fn>void <a name="setRegExp"></a>QRegExpValidator::setRegExp ( const <a href="qregexp.html">QRegExp</a> & rx )
|
---|
135 | </h3>
|
---|
136 | Sets the <a href="qregexp.html#regular-expression">regular expression</a> used for validation to <em>rx</em>.
|
---|
137 | <p> <p>See also <a href="#regExp">regExp</a>().
|
---|
138 |
|
---|
139 | <h3 class=fn><a href="qvalidator.html#State-enum">QValidator::State</a> <a name="validate"></a>QRegExpValidator::validate ( <a href="qstring.html">QString</a> & input, int & pos ) const<tt> [virtual]</tt>
|
---|
140 | </h3>
|
---|
141 | Returns <a href="qvalidator.html#State-enum">Acceptable</a> if <em>input</em> is matched by the <a href="qregexp.html#regular-expression">regular expression</a> for this validator, <a href="qvalidator.html#State-enum">Intermediate</a> if it has matched
|
---|
142 | partially (i.e. could be a valid match if additional valid
|
---|
143 | characters are added), and <a href="qvalidator.html#State-enum">Invalid</a> if <em>input</em> is not matched.
|
---|
144 | <p> The <em>pos</em> parameter is set to the length of the <em>input</em> parameter.
|
---|
145 | <p> For example, if the regular expression is <b>\w\d\d</b> (that
|
---|
146 | is, word-character, digit, digit) then "A57" is <a href="qvalidator.html#State-enum">Acceptable</a>,
|
---|
147 | "E5" is <a href="qvalidator.html#State-enum">Intermediate</a> and "+9" is <a href="qvalidator.html#State-enum">Invalid</a>.
|
---|
148 | <p> <p>See also <a href="qregexp.html#match">QRegExp::match</a>() and <a href="qregexp.html#search">QRegExp::search</a>().
|
---|
149 |
|
---|
150 | <p>Reimplemented from <a href="qvalidator.html#validate">QValidator</a>.
|
---|
151 | <!-- eof -->
|
---|
152 | <hr><p>
|
---|
153 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
154 | Copyright © 1995-2007
|
---|
155 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
156 | <table width=100% cellspacing=0 border=0><tr>
|
---|
157 | <td>Copyright © 2007
|
---|
158 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
159 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
160 | </table></div></address></body>
|
---|
161 | </html>
|
---|