You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
9.2 KiB
162 lines
9.2 KiB
13 years ago
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/widgets/qvalidator.cpp:517 -->
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
|
<title>TQRegExpValidator Class</title>
|
||
|
<style type="text/css"><!--
|
||
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
||
|
a:link { color: #004faf; text-decoration: none }
|
||
|
a:visited { color: #672967; text-decoration: none }
|
||
|
body { background: #ffffff; color: black; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||
|
<tr bgcolor="#E5E5E5">
|
||
|
<td valign=center>
|
||
|
<a href="index.html">
|
||
|
<font color="#004faf">Home</font></a>
|
||
|
| <a href="classes.html">
|
||
|
<font color="#004faf">All Classes</font></a>
|
||
|
| <a href="mainclasses.html">
|
||
|
<font color="#004faf">Main Classes</font></a>
|
||
|
| <a href="annotated.html">
|
||
|
<font color="#004faf">Annotated</font></a>
|
||
|
| <a href="groups.html">
|
||
|
<font color="#004faf">Grouped Classes</font></a>
|
||
|
| <a href="functions.html">
|
||
|
<font color="#004faf">Functions</font></a>
|
||
|
</td>
|
||
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQRegExpValidator Class Reference</h1>
|
||
|
|
||
|
<p>The TQRegExpValidator class is used to check a string
|
||
|
against a regular expression.
|
||
|
<a href="#details">More...</a>
|
||
13 years ago
|
<p><tt>#include <<a href="qvalidator-h.html">ntqvalidator.h</a>></tt>
|
||
|
<p>Inherits <a href="ntqvalidator.html">TQValidator</a>.
|
||
5 months ago
|
<p><a href="tqregexpvalidator-members.html">List of all member functions.</a>
|
||
13 years ago
|
<h2>Public Members</h2>
|
||
|
<ul>
|
||
|
<li class=fn><a href="#TQRegExpValidator"><b>TQRegExpValidator</b></a> ( TQObject * parent, const char * name = 0 )</li>
|
||
|
<li class=fn><a href="#TQRegExpValidator-2"><b>TQRegExpValidator</b></a> ( const TQRegExp & rx, TQObject * parent, const char * name = 0 )</li>
|
||
|
<li class=fn><a href="#~TQRegExpValidator"><b>~TQRegExpValidator</b></a> ()</li>
|
||
|
<li class=fn>virtual TQValidator::State <a href="#validate"><b>validate</b></a> ( TQString & input, int & pos ) const</li>
|
||
|
<li class=fn>void <a href="#setRegExp"><b>setRegExp</b></a> ( const TQRegExp & rx )</li>
|
||
|
<li class=fn>const TQRegExp & <a href="#regExp"><b>regExp</b></a> () const</li>
|
||
|
</ul>
|
||
|
<hr><a name="details"></a><h2>Detailed Description</h2>
|
||
|
|
||
|
|
||
|
The TQRegExpValidator class is used to check a string
|
||
5 months ago
|
against a <a href="tqregexp.html#regular-expression">regular expression</a>.
|
||
13 years ago
|
<p>
|
||
|
<p> TQRegExpValidator contains a regular expression, "regexp", used to
|
||
13 years ago
|
determine whether an input string is <a href="ntqvalidator.html#State-enum">Acceptable</a>, <a href="ntqvalidator.html#State-enum">Intermediate</a> or <a href="ntqvalidator.html#State-enum">Invalid</a>.
|
||
13 years ago
|
<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.
|
||
5 months ago
|
<p> For a brief introduction to TQt's regexp engine see <a href="tqregexp.html">TQRegExp</a>.
|
||
13 years ago
|
<p> Example of use:
|
||
|
<pre>
|
||
|
// regexp: optional '-' followed by between 1 and 3 digits
|
||
5 months ago
|
<a href="tqregexp.html">TQRegExp</a> rx( "-?\\d{1,3}" );
|
||
13 years ago
|
<a href="ntqvalidator.html">TQValidator</a>* validator = new TQRegExpValidator( rx, this );
|
||
13 years ago
|
|
||
13 years ago
|
<a href="ntqlineedit.html">TQLineEdit</a>* edit = new <a href="ntqlineedit.html">TQLineEdit</a>( this );
|
||
|
edit-><a href="ntqlineedit.html#setValidator">setValidator</a>( validator );
|
||
13 years ago
|
</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
|
||
5 months ago
|
<a href="tqregexp.html">TQRegExp</a> rx( "[1-9]\\d{0,3}" );
|
||
13 years ago
|
// the validator treats the regexp as "^[1-9]\\d{0,3}$"
|
||
|
TQRegExpValidator v( rx, 0 );
|
||
6 months ago
|
<a href="tqstring.html">TQString</a> s;
|
||
13 years ago
|
int pos = 0;
|
||
|
|
||
|
s = "0"; v.<a href="#validate">validate</a>( s, pos ); // returns Invalid
|
||
|
s = "12345"; v.<a href="#validate">validate</a>( s, pos ); // returns Invalid
|
||
|
s = "1"; v.<a href="#validate">validate</a>( s, pos ); // returns Acceptable
|
||
|
|
||
5 months ago
|
rx.<a href="tqregexp.html#setPattern">setPattern</a>( "\\S+" ); // one or more non-whitespace characters
|
||
13 years ago
|
v.<a href="#setRegExp">setRegExp</a>( rx );
|
||
|
s = "myfile.txt"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
||
|
s = "my file.txt"; v.<a href="#validate">validate</a>( s, pos ); // Returns Invalid
|
||
|
|
||
|
// A, B or C followed by exactly five digits followed by W, X, Y or Z
|
||
5 months ago
|
rx.<a href="tqregexp.html#setPattern">setPattern</a>( "[A-C]\\d{5}[W-Z]" );
|
||
13 years ago
|
v.<a href="#setRegExp">setRegExp</a>( rx );
|
||
|
s = "a12345Z"; v.<a href="#validate">validate</a>( s, pos ); // Returns Invalid
|
||
|
s = "A12345Z"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
||
|
s = "B12"; v.<a href="#validate">validate</a>( s, pos ); // Returns Intermediate
|
||
|
|
||
|
// match most 'readme' files
|
||
5 months ago
|
rx.<a href="tqregexp.html#setPattern">setPattern</a>( "read\\S?me(\.(txt|asc|1st))?" );
|
||
|
rx.<a href="tqregexp.html#setCaseSensitive">setCaseSensitive</a>( FALSE );
|
||
13 years ago
|
v.<a href="#setRegExp">setRegExp</a>( rx );
|
||
|
s = "readme"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
||
|
s = "README.1ST"; v.<a href="#validate">validate</a>( s, pos ); // Returns Acceptable
|
||
|
s = "read me.txt"; v.<a href="#validate">validate</a>( s, pos ); // Returns Invalid
|
||
|
s = "readm"; v.<a href="#validate">validate</a>( s, pos ); // Returns Intermediate
|
||
|
</pre>
|
||
|
|
||
5 months ago
|
<p> <p>See also <a href="tqregexp.html">TQRegExp</a>, <a href="qintvalidator.html">TQIntValidator</a>, <a href="qdoublevalidator.html">TQDoubleValidator</a>, and <a href="misc.html">Miscellaneous Classes</a>.
|
||
13 years ago
|
|
||
|
<hr><h2>Member Function Documentation</h2>
|
||
6 months ago
|
<h3 class=fn><a name="TQRegExpValidator"></a>TQRegExpValidator::TQRegExpValidator ( <a href="tqobject.html">TQObject</a> * parent, const char * name = 0 )
|
||
13 years ago
|
</h3>
|
||
|
Constructs a validator that accepts any string (including an empty
|
||
|
one) as valid. The object's parent is <em>parent</em> and its name is <em>name</em>.
|
||
|
|
||
5 months ago
|
<h3 class=fn><a name="TQRegExpValidator-2"></a>TQRegExpValidator::TQRegExpValidator ( const <a href="tqregexp.html">TQRegExp</a> & rx, <a href="tqobject.html">TQObject</a> * parent, const char * name = 0 )
|
||
13 years ago
|
</h3>
|
||
|
Constructs a validator which accepts all strings that match the
|
||
5 months ago
|
<a href="tqregexp.html#regular-expression">regular expression</a> <em>rx</em>. The object's parent is <em>parent</em> and its
|
||
13 years ago
|
name is <em>name</em>.
|
||
|
<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>.
|
||
|
|
||
|
<h3 class=fn><a name="~TQRegExpValidator"></a>TQRegExpValidator::~TQRegExpValidator ()
|
||
|
</h3>
|
||
|
Destroys the validator, freeing any resources allocated.
|
||
|
|
||
5 months ago
|
<h3 class=fn>const <a href="tqregexp.html">TQRegExp</a> & <a name="regExp"></a>TQRegExpValidator::regExp () const
|
||
13 years ago
|
</h3>
|
||
|
|
||
5 months ago
|
<p> Returns the <a href="tqregexp.html#regular-expression">regular expression</a> used for validation.
|
||
13 years ago
|
<p> <p>See also <a href="#setRegExp">setRegExp</a>().
|
||
|
|
||
5 months ago
|
<h3 class=fn>void <a name="setRegExp"></a>TQRegExpValidator::setRegExp ( const <a href="tqregexp.html">TQRegExp</a> & rx )
|
||
13 years ago
|
</h3>
|
||
5 months ago
|
Sets the <a href="tqregexp.html#regular-expression">regular expression</a> used for validation to <em>rx</em>.
|
||
13 years ago
|
<p> <p>See also <a href="#regExp">regExp</a>().
|
||
|
|
||
6 months ago
|
<h3 class=fn><a href="ntqvalidator.html#State-enum">TQValidator::State</a> <a name="validate"></a>TQRegExpValidator::validate ( <a href="tqstring.html">TQString</a> & input, int & pos ) const<tt> [virtual]</tt>
|
||
13 years ago
|
</h3>
|
||
5 months ago
|
Returns <a href="ntqvalidator.html#State-enum">Acceptable</a> if <em>input</em> is matched by the <a href="tqregexp.html#regular-expression">regular expression</a> for this validator, <a href="ntqvalidator.html#State-enum">Intermediate</a> if it has matched
|
||
13 years ago
|
partially (i.e. could be a valid match if additional valid
|
||
13 years ago
|
characters are added), and <a href="ntqvalidator.html#State-enum">Invalid</a> if <em>input</em> is not matched.
|
||
13 years ago
|
<p> The <em>pos</em> parameter is set to the length of the <em>input</em> parameter.
|
||
|
<p> For example, if the regular expression is <b>\w\d\d</b> (that
|
||
13 years ago
|
is, word-character, digit, digit) then "A57" is <a href="ntqvalidator.html#State-enum">Acceptable</a>,
|
||
|
"E5" is <a href="ntqvalidator.html#State-enum">Intermediate</a> and "+9" is <a href="ntqvalidator.html#State-enum">Invalid</a>.
|
||
5 months ago
|
<p> <p>See also <a href="tqregexp.html#match">TQRegExp::match</a>() and <a href="tqregexp.html#search">TQRegExp::search</a>().
|
||
13 years ago
|
|
||
13 years ago
|
<p>Reimplemented from <a href="ntqvalidator.html#validate">TQValidator</a>.
|
||
13 years ago
|
<!-- eof -->
|
||
|
<hr><p>
|
||
|
This file is part of the <a href="index.html">TQt toolkit</a>.
|
||
|
Copyright © 1995-2007
|
||
|
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
||
|
<table width=100% cellspacing=0 border=0><tr>
|
||
|
<td>Copyright © 2007
|
||
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
||
|
<td align=right><div align=right>TQt 3.3.8</div>
|
||
|
</table></div></address></body>
|
||
|
</html>
|