source: trunk/doc/html/qregexpvalidator.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.3 KB
Line 
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"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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
35against a regular expression.
36<a href="#details">More...</a>
37<p><tt>#include &lt;<a href="qvalidator-h.html">qvalidator.h</a>&gt;</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&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
43<li class=fn><a href="#QRegExpValidator-2"><b>QRegExpValidator</b></a> ( const&nbsp;QRegExp&nbsp;&amp;&nbsp;rx, QObject&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;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&nbsp;&amp;&nbsp;input, int&nbsp;&amp;&nbsp;pos ) const</li>
46<li class=fn>void <a href="#setRegExp"><b>setRegExp</b></a> ( const&nbsp;QRegExp&nbsp;&amp;&nbsp;rx )</li>
47<li class=fn>const QRegExp &amp; <a href="#regExp"><b>regExp</b></a> () const</li>
48</ul>
49<hr><a name="details"></a><h2>Detailed Description</h2>
50
51
52The QRegExpValidator class is used to check a string
53against a <a href="qregexp.html#regular-expression">regular expression</a>.
54<p>
55<p> QRegExpValidator contains a regular expression, "regexp", used to
56determine 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
58assertion, <b>^</b>, and ends with the end of string assertion
59<b>$</b> so the match is against the entire input string, or from
60the 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-&gt;<a href="qlineedit.html#setValidator">setValidator</a>( validator );
70 </pre>
71
72<p> Below we present some examples of validators. In practice they would
73normally 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>&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name = 0 )
112</h3>
113Constructs a validator that accepts any string (including an empty
114one) 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&nbsp;<a href="qregexp.html">QRegExp</a>&nbsp;&amp;&nbsp;rx, <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name = 0 )
117</h3>
118Constructs 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
120name 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>
126Destroys the validator, freeing any resources allocated.
127
128<h3 class=fn>const&nbsp;<a href="qregexp.html">QRegExp</a>&nbsp;&amp; <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&nbsp;<a href="qregexp.html">QRegExp</a>&nbsp;&amp;&nbsp;rx )
135</h3>
136Sets 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>&nbsp;&amp;&nbsp;input, int&nbsp;&amp;&nbsp;pos ) const<tt> [virtual]</tt>
140</h3>
141Returns <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
142partially (i.e. could be a valid match if additional valid
143characters 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>&#92;w&#92;d&#92;d</b> (that
146is, 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>
153This file is part of the <a href="index.html">Qt toolkit</a>.
154Copyright &copy; 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 &copy; 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>
Note: See TracBrowser for help on using the repository browser.