File: qregexpvalidator.html

package info (click to toggle)
qt4-x11 4%3A4.8.2%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 701,696 kB
  • sloc: cpp: 2,686,179; ansic: 375,485; python: 25,859; sh: 19,349; xml: 17,091; perl: 14,765; yacc: 5,383; asm: 5,038; makefile: 1,259; lex: 555; ruby: 526; objc: 347; cs: 112; pascal: 112; php: 54; sed: 34
file content (189 lines) | stat: -rw-r--r-- 16,291 bytes parent folder | download
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
180
181
182
183
184
185
186
187
188
189
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qvalidator.cpp -->
  <title>Qt 4.8: QRegExpValidator Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtgui.html">QtGui</a></li>
<li>QRegExpValidator</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#properties">Properties</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QRegExpValidator Class Reference</h1>
<!-- $$$QRegExpValidator-brief -->
<p>The QRegExpValidator class is used to check a string against a regular expression. <a href="#details">More...</a></p>
<!-- @@@QRegExpValidator -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QRegExpValidator&gt;</span></pre><p><b>Inherits: </b><a href="qvalidator.html">QValidator</a>.</p>
<ul>
<li><a href="qregexpvalidator-members.html">List of all members, including inherited members</a></li>
<li><a href="qregexpvalidator-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="properties"></a>
<h2>Properties</h2>
<ul>
<li class="fn"><b><a href="qregexpvalidator.html#regExp-prop">regExp</a></b> : QRegExp</li>
</ul>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qregexpvalidator.html#QRegExpValidator">QRegExpValidator</a></b> ( QObject * <i>parent</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qregexpvalidator.html#QRegExpValidator-2">QRegExpValidator</a></b> ( const QRegExp &amp; <i>rx</i>, QObject * <i>parent</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qregexpvalidator.html#dtor.QRegExpValidator">~QRegExpValidator</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QRegExp &amp; </td><td class="memItemRight bottomAlign"><b><a href="qregexpvalidator.html#regExp-prop">regExp</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qregexpvalidator.html#regExp-prop">setRegExp</a></b> ( const QRegExp &amp; <i>rx</i> )</td></tr>
</table>
<a name="reimplemented-public-functions"></a>
<h2>Reimplemented Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual QValidator::State </td><td class="memItemRight bottomAlign"><b><a href="qregexpvalidator.html#validate">validate</a></b> ( QString &amp; <i>input</i>, int &amp; <i>pos</i> ) const</td></tr>
</table>
<ul>
<li class="fn">4 public functions inherited from <a href="qvalidator.html#public-functions">QValidator</a></li>
<li class="fn">29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li class="fn">1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li class="fn">7 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li class="fn">8 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QRegExpValidator-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>The QRegExpValidator class is used to check a string against a regular expression.</p>
<p>QRegExpValidator uses a regular expression (regexp) to 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>. The regexp can either be supplied when the QRegExpValidator is constructed, or at a later time.</p>
<p>When QRegExpValidator determines whether a string is <a href="qvalidator.html#State-enum">Acceptable</a> or not, the regexp is treated as if it begins with the start of string assertion (<b>^</b>) and ends with the end of string assertion (<b>$</b>); the match is against the entire input string, or from the given position if a start position greater than zero is given.</p>
<p>If a string is a prefix of an <a href="qvalidator.html#State-enum">Acceptable</a> string, it is considered <a href="qvalidator.html#State-enum">Intermediate</a>. For example, &quot;&quot; and &quot;A&quot; are <a href="qvalidator.html#State-enum">Intermediate</a> for the regexp <b>[A-Z][0-9]</b> (whereas &quot;<a href="index.html">_</a>&quot; would be <a href="qvalidator.html#State-enum">Invalid</a>).</p>
<p>For a brief introduction to Qt's regexp engine, see <a href="qregexp.html">QRegExp</a>.</p>
<p>Example of use:</p>
<pre class="cpp"> <span class="comment">// regexp: optional '-' followed by between 1 and 3 digits</span>
 <span class="type"><a href="qregexp.html">QRegExp</a></span> rx(<span class="string">&quot;-?\\d{1,3}&quot;</span>);
 <span class="type"><a href="qvalidator.html">QValidator</a></span> <span class="operator">*</span>validator <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QRegExpValidator</span>(rx<span class="operator">,</span> <span class="keyword">this</span>);

 <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>edit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>(<span class="keyword">this</span>);
 edit<span class="operator">-</span><span class="operator">&gt;</span>setValidator(validator);</pre>
<p>Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above.</p>
<pre class="cpp"> <span class="comment">// integers 1 to 9999</span>
 <span class="type"><a href="qregexp.html">QRegExp</a></span> rx(<span class="string">&quot;[1-9]\\d{0,3}&quot;</span>);
 <span class="comment">// the validator treats the regexp as &quot;^[1-9]\\d{0,3}$&quot;</span>
 <span class="type">QRegExpValidator</span> v(rx<span class="operator">,</span> <span class="number">0</span>);
 <span class="type"><a href="qstring.html">QString</a></span> s;
 <span class="type">int</span> pos <span class="operator">=</span> <span class="number">0</span>;

 s <span class="operator">=</span> <span class="string">&quot;0&quot;</span>;     v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos);    <span class="comment">// returns Invalid</span>
 s <span class="operator">=</span> <span class="string">&quot;12345&quot;</span>; v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos);    <span class="comment">// returns Invalid</span>
 s <span class="operator">=</span> <span class="string">&quot;1&quot;</span>;     v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos);    <span class="comment">// returns Acceptable</span>

 rx<span class="operator">.</span>setPattern(<span class="string">&quot;\\S+&quot;</span>);            <span class="comment">// one or more non-whitespace characters</span>
 v<span class="operator">.</span><a href="qregexpvalidator.html#regExp-prop">setRegExp</a>(rx);
 s <span class="operator">=</span> <span class="string">&quot;myfile.txt&quot;</span>;  v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos); <span class="comment">// Returns Acceptable</span>
 s <span class="operator">=</span> <span class="string">&quot;my file.txt&quot;</span>; v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos); <span class="comment">// Returns Invalid</span>

 <span class="comment">// A, B or C followed by exactly five digits followed by W, X, Y or Z</span>
 rx<span class="operator">.</span>setPattern(<span class="string">&quot;[A-C]\\d{5}[W-Z]&quot;</span>);
 v<span class="operator">.</span><a href="qregexpvalidator.html#regExp-prop">setRegExp</a>(rx);
 s <span class="operator">=</span> <span class="string">&quot;a12345Z&quot;</span>; v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos);        <span class="comment">// Returns Invalid</span>
 s <span class="operator">=</span> <span class="string">&quot;A12345Z&quot;</span>; v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos);        <span class="comment">// Returns Acceptable</span>
 s <span class="operator">=</span> <span class="string">&quot;B12&quot;</span>;     v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos);        <span class="comment">// Returns Intermediate</span>

 <span class="comment">// match most 'readme' files</span>
 rx<span class="operator">.</span>setPattern(<span class="string">&quot;read\\S?me(\.(txt|asc|1st))?&quot;</span>);
 rx<span class="operator">.</span>setCaseSensitive(<span class="keyword">false</span>);
 v<span class="operator">.</span><a href="qregexpvalidator.html#regExp-prop">setRegExp</a>(rx);
 s <span class="operator">=</span> <span class="string">&quot;readme&quot;</span>;      v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos); <span class="comment">// Returns Acceptable</span>
 s <span class="operator">=</span> <span class="string">&quot;README.1ST&quot;</span>;  v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos); <span class="comment">// Returns Acceptable</span>
 s <span class="operator">=</span> <span class="string">&quot;read me.txt&quot;</span>; v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos); <span class="comment">// Returns Invalid</span>
 s <span class="operator">=</span> <span class="string">&quot;readm&quot;</span>;       v<span class="operator">.</span><a href="qregexpvalidator.html#validate">validate</a>(s<span class="operator">,</span> pos); <span class="comment">// Returns Intermediate</span></pre>
</div>
<p><b>See also </b><a href="qregexp.html">QRegExp</a>, <a href="qintvalidator.html">QIntValidator</a>, <a href="qdoublevalidator.html">QDoubleValidator</a>, and <a href="tools-settingseditor.html">Settings Editor Example</a>.</p>
<!-- @@@QRegExpValidator -->
<div class="prop">
<h2>Property Documentation</h2>
<!-- $$$regExp-prop$$$regExp$$$setRegExpconstQRegExp& -->
<h3 class="fn"><a name="regExp-prop"></a><span class="name">regExp</span> : <span class="type"><a href="qregexp.html">QRegExp</a></span></h3>
<p>This property holds the regular expression used for validation.</p>
<p>By default, this property contains a regular expression with the pattern <tt>.*</tt> that matches any string.</p>
<p><b>Access functions:</b></p>
<table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> const QRegExp &amp; </td><td class="memItemRight bottomAlign"><span class="name"><b>regExp</b></span> () const</td></tr>
<tr><td class="memItemLeft topAlign rightAlign"> void </td><td class="memItemRight bottomAlign"><span class="name"><b>setRegExp</b></span> ( const QRegExp &amp; <i>rx</i> )</td></tr>
</table>
<!-- @@@regExp -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QRegExpValidator[overload1]$$$QRegExpValidatorQObject* -->
<h3 class="fn"><a name="QRegExpValidator"></a>QRegExpValidator::<span class="name">QRegExpValidator</span> ( <span class="type"><a href="qobject.html">QObject</a></span> * <i>parent</i> = 0 )</h3>
<p>Constructs a validator with a <i>parent</i> object that accepts any string (including an empty one) as valid.</p>
<!-- @@@QRegExpValidator -->
<!-- $$$QRegExpValidator$$$QRegExpValidatorconstQRegExp&QObject* -->
<h3 class="fn"><a name="QRegExpValidator-2"></a>QRegExpValidator::<span class="name">QRegExpValidator</span> ( const <span class="type"><a href="qregexp.html">QRegExp</a></span> &amp; <i>rx</i>, <span class="type"><a href="qobject.html">QObject</a></span> * <i>parent</i> = 0 )</h3>
<p>Constructs a validator with a <i>parent</i> object that accepts all strings that match the regular expression <i>rx</i>.</p>
<p>The match is made against the entire string; e.g&#x2e; if the regexp is <b>[A-Fa-f0-9]+</b> it will be treated as <b>^[A-Fa-f0-9]+$</b>.</p>
<!-- @@@QRegExpValidator -->
<!-- $$$~QRegExpValidator[overload1]$$$~QRegExpValidator -->
<h3 class="fn"><a name="dtor.QRegExpValidator"></a>QRegExpValidator::<span class="name">~QRegExpValidator</span> ()</h3>
<p>Destroys the validator.</p>
<!-- @@@~QRegExpValidator -->
<!-- $$$validate[overload1]$$$validateQString&int& -->
<h3 class="fn"><a name="validate"></a><span class="type"><a href="qvalidator.html#State-enum">QValidator::State</a></span> QRegExpValidator::<span class="name">validate</span> ( <span class="type"><a href="qstring.html">QString</a></span> &amp; <i>input</i>, <span class="type">int</span> &amp; <i>pos</i> ) const<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qvalidator.html#validate">QValidator::validate</a>().</p>
<p>Returns <a href="qvalidator.html#State-enum">Acceptable</a> if <i>input</i> is matched by the regular expression for this validator, <a href="qvalidator.html#State-enum">Intermediate</a> if it has matched partially (i.e&#x2e; could be a valid match if additional valid characters are added), and <a href="qvalidator.html#State-enum">Invalid</a> if <i>input</i> is not matched.</p>
<p>The <i>pos</i> parameter is set to the length of the <i>input</i> parameter.</p>
<p>For example, if the regular expression is <b>\w\d\d</b> (word-character, digit, digit) then &quot;A57&quot; is <a href="qvalidator.html#State-enum">Acceptable</a>, &quot;E5&quot; is <a href="qvalidator.html#State-enum">Intermediate</a>, and &quot;+9&quot; is <a href="qvalidator.html#State-enum">Invalid</a>.</p>
<p><b>See also </b><a href="qregexp.html#exactMatch">QRegExp::exactMatch</a>().</p>
<!-- @@@validate -->
</div>
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2012 Nokia Corporation and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>