File: qregexpvalidator.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (66 lines) | stat: -rw-r--r-- 7,583 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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QRegExpValidator Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QRegExpValidator Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QRegExpValidator class is used to check a string against a regular expression. <a href="#details">More...</a></p>
<p>Inherits <a href="qvalidator.html">QValidator</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qregexpvalidator.html#QRegExpValidator">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" /><b><a href="qregexpvalidator.html#QRegExpValidator-2">__init__</a></b> (<i>self</i>, QRegExp&#160;<i>rx</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" />QRegExp <b><a href="qregexpvalidator.html#regExp">regExp</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qregexpvalidator.html#setRegExp">setRegExp</a></b> (<i>self</i>, QRegExp&#160;<i>rx</i>)</li><li><div class="fn" />(QValidator.State, int&#160;<i>pos</i>) <b><a href="qregexpvalidator.html#validate">validate</a></b> (<i>self</i>, QString&#160;<i>input</i>, int&#160;<i>pos</i>)</li></ul><a name="details" /><hr /><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>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> so the match is against the entire input string, or from the given position if a start position greater than zero is given.</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>
    // regexp: optional '-' followed by between 1 and 3 digits
    QRegExp rx("-?\\d{1,3}");
    QValidator *validator = new QRegExpValidator(rx, this);

    QLineEdit *edit = new QLineEdit(this);
    edit-&gt;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>
    // integers 1 to 9999
    QRegExp rx("[1-9]\\d{0,3}");
    // the validator treats the regexp as "^[1-9]\\d{0,3}$"
    QRegExpValidator v(rx, 0);
    QString s;
    int pos = 0;

    s = "0";     v.validate(s, pos);    // returns Invalid
    s = "12345"; v.validate(s, pos);    // returns Invalid
    s = "1";     v.validate(s, pos);    // returns Acceptable

    rx.setPattern("\\S+");            // one or more non-whitespace characters
    v.setRegExp(rx);
    s = "myfile.txt";  v.validate(s, pos); // Returns Acceptable
    s = "my file.txt"; v.validate(s, pos); // Returns Invalid

    // A, B or C followed by exactly five digits followed by W, X, Y or Z
    rx.setPattern("[A-C]\\d{5}[W-Z]");
    v.setRegExp(rx);
    s = "a12345Z"; v.validate(s, pos);        // Returns Invalid
    s = "A12345Z"; v.validate(s, pos);        // Returns Acceptable
    s = "B12";     v.validate(s, pos);        // Returns Intermediate

    // match most 'readme' files
    rx.setPattern("read\\S?me(\.(txt|asc|1st))?");
    rx.setCaseSensitive(false);
    v.setRegExp(rx);
    s = "readme";      v.validate(s, pos); // Returns Acceptable
    s = "README.1ST";  v.validate(s, pos); // Returns Acceptable
    s = "read me.txt"; v.validate(s, pos); // Returns Invalid
    s = "readm";       v.validate(s, pos); // Returns Intermediate
</pre>
<p>See also <a href="qregexp.html">QRegExp</a>, <a href="qintvalidator.html">QIntValidator</a>, and <a href="qdoublevalidator.html">QDoubleValidator</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QRegExpValidator" />QRegExpValidator.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a validator with a <i>parent</i> object that accepts any string (including an empty one) as valid.</p>
<h3 class="fn"><a name="QRegExpValidator-2" />QRegExpValidator.__init__ (<i>self</i>, <a href="qregexp.html">QRegExp</a>&#160;<i>rx</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><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. if the regexp is <b>[A-Fa-f0-9]+</b> it will be treated as <b>^[A-Fa-f0-9]+$</b>.</p>
<h3 class="fn"><a name="regExp" /><a href="qregexp.html">QRegExp</a> QRegExpValidator.regExp (<i>self</i>)</h3><h3 class="fn"><a name="setRegExp" />QRegExpValidator.setRegExp (<i>self</i>, <a href="qregexp.html">QRegExp</a>&#160;<i>rx</i>)</h3><h3 class="fn"><a name="validate" />(<a href="qvalidator.html#State-enum">QValidator.State</a>, int&#160;<i>pos</i>) QRegExpValidator.validate (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>input</i>, int&#160;<i>pos</i>)</h3><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. 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 "A57" is <a href="qvalidator.html#State-enum">Acceptable</a>, "E5" is <a href="qvalidator.html#State-enum">Intermediate</a>, and "+9" is <a href="qvalidator.html#State-enum">Invalid</a>.</p>
<p>Reimplemented from <a href="qvalidator.html#validate">QValidator</a>.</p>
<p>See also <a href="qregexp.html#exactMatch">QRegExp.exactMatch</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>