qregexpvalidator.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 164 行
HTML
164 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/widgets/qvalidator.cpp:500 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QRegExpValidator Class</title><style type="text/css"><!--h3.fn,span.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>QRegExpValidator Class Reference</h1><p>The QRegExpValidator class is used to check a string against aregular expression.<a href="#details">More...</a><p><tt>#include <<a href="qvalidator-h.html">qvalidator.h</a>></tt><p>Inherits <a href="qvalidator.html">QValidator</a>.<p><a href="qregexpvalidator-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QRegExpValidator"><b>QRegExpValidator</b></a> ( QObject * parent, const char * name = 0 )</div></li><li><div class=fn><a href="#QRegExpValidator-2"><b>QRegExpValidator</b></a> ( const QRegExp & rx, QObject * parent, const char * name = 0 )</div></li><li><div class=fn><a href="#~QRegExpValidator"><b>~QRegExpValidator</b></a> ()</div></li><li><div class=fn>virtual QValidator::State <a href="#validate"><b>validate</b></a> ( QString & input, int & pos ) const</div></li><li><div class=fn>void <a href="#setRegExp"><b>setRegExp</b></a> ( const QRegExp & rx )</div></li><li><div class=fn>const QRegExp & <a href="#regExp"><b>regExp</b></a> () const</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2><p> The QRegExpValidator class is used to check a string against a<a href="qregexp.html#regular-expression">regular expression</a>.<p> <p> QRegExpValidator contains a regular expression, "regexp", used todetermine 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>.<p> The regexp is treated as if it begins with the start of stringassertion, <tt>^</tt>, and ends with the end of string assertion<tt>$</tt> so the match is against the entire input string, or fromthe given position if a start position greater than zero is given.<p> For a brief introduction to Qt's regexp engine see <a href="qregexp.html">QRegExp</a>.<p> Example of use:<pre> // regexp: optional '-' followed by between 1 and 3 digits <a href="qregexp.html">QRegExp</a> rx( "-?\\d{1,3}" ); QRegExpValidator validator( rx, 0 ); <a href="qlineedit.html">QLineEdit</a> *edit = new <a href="qlineedit.html">QLineEdit</a>( split ); edit-><a href="qlineedit.html#setValidator">setValidator</a>( &validator ); </pre> <p> Below we present some examples of validators. In practice they wouldnormally be associated with a widget as in the example above.<p> <pre> // integers 1 to 9999 <a href="qregexp.html">QRegExp</a> rx( "[1-9]\\d{0,3}" ); // the validator treats the regexp as "^[1-9]\\d{0,3}$" QRegExpValidator v( rx, 0 ); <a href="qstring.html">QString</a> s; s = "0"; v.<a href="#validate">validate</a>( s, 0 ); // returns Invalid s = "12345"; v.<a href="#validate">validate</a>( s, 0 ); // returns Invalid s = "1"; v.<a href="#validate">validate</a>( s, 0 ); // returns Acceptable rx.<a href="qregexp.html#setPattern">setPattern</a>( "\\S+" ); // one or more non-whitespace characters v.<a href="#setRegExp">setRegExp</a>( rx ); s = "myfile.txt"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Acceptable s = "my file.txt"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Invalid // A, B or C followed by exactly five digits followed by W, X, Y or Z rx.<a href="qregexp.html#setPattern">setPattern</a>( "[A-C]\\d{5}[W-Z]" ); v.<a href="#setRegExp">setRegExp</a>( rx ); s = "a12345Z"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Invalid s = "A12345Z"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Acceptable s = "B12"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Intermediate // match most 'readme' files rx.<a href="qregexp.html#setPattern">setPattern</a>( "read\\S?me(\.(txt|asc|1st))?" ); rx.<a href="qregexp.html#setCaseSensitive">setCaseSensitive</a>( FALSE ); v.<a href="#setRegExp">setRegExp</a>( rx ); s = "readme"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Acceptable s = "README.1ST"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Acceptable s = "read me.txt"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Invalid s = "readm"; v.<a href="#validate">validate</a>( s, 0 ); // Returns Intermediate </pre> <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>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QRegExpValidator"></a>QRegExpValidator::QRegExpValidator ( <a href="qobject.html">QObject</a> * parent, const char * name = 0 )</h3>Constructs a validator that accepts any string (including anempty one) as valid. The object's parent is <em>parent</em> and its name is <em>name</em>.<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 )</h3>Constructs a validator which accepts all strings that match the<a href="qregexp.html#regular-expression">regular expression</a> <em>rx</em>. The object's parent is <em>parent</em> and its 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="~QRegExpValidator"></a>QRegExpValidator::~QRegExpValidator ()</h3>Destroys the validator, freeing any resources allocated.<h3 class=fn>const <a href="qregexp.html">QRegExp</a> & <a name="regExp"></a>QRegExpValidator::regExp () const</h3> <p> Returns the <a href="qregexp.html#regular-expression">regular expression</a> used for validation.<p> <p>See also <a href="#setRegExp">setRegExp</a>().<h3 class=fn>void <a name="setRegExp"></a>QRegExpValidator::setRegExp ( const <a href="qregexp.html">QRegExp</a> & rx )</h3>Sets the <a href="qregexp.html#regular-expression">regular expression</a> used for validation to <em>rx</em>.<p> <p>See also <a href="#regExp">regExp</a>().<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></h3>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 partially (i.e.could be a valid match if additional valid characters are added), and<a href="qvalidator.html#State-enum">Invalid</a> if <em>input</em> is not matched.<p> The start position is the beginning of the string unless <em>pos</em> isgiven and is > 0 in which case the regexp is matched from <em>pos</em> untilthe end of the string.<p> For example, if the regular expression is<b>\w\d\d</b> (that is, 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>See also <a href="qregexp.html#match">QRegExp::match</a>().<p>Reimplemented from <a href="qvalidator.html#validate">QValidator</a>.<!-- eof --><hr><p>This file is part of the <a href="index.html">Qt toolkit</a>.Copyright © 1995-2002<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 © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?