<class name="QRegExpValidator" doc="/** <p>The <a href="QRegExpValidator.html#QRegExpValidator(com.trolltech.qt.core.QRegExp, com.trolltech.qt.core.QObject)"><tt>QRegExpValidator</tt></a> class is used to check a string against a regular expression.</p> <p><a href="QRegExpValidator.html#QRegExpValidator(com.trolltech.qt.core.QRegExp, com.trolltech.qt.core.QObject)"><tt>QRegExpValidator</tt></a> uses a regular expression (regexp) to determine whether an input string is <a href="QValidator.html#State-enum">Acceptable</tt></a>, <a href="QValidator.html#State-enum">Intermediate</tt></a>, or <a href="QValidator.html#State-enum">Invalid</tt></a>. The regexp can either be supplied when the <a href="QRegExpValidator.html#QRegExpValidator(com.trolltech.qt.core.QRegExp, com.trolltech.qt.core.QObject)"><tt>QRegExpValidator</tt></a> is constructed, or at a later time.</p> <p>When <a href="QRegExpValidator.html#QRegExpValidator(com.trolltech.qt.core.QRegExp, com.trolltech.qt.core.QObject)"><tt>QRegExpValidator</tt></a> determines whether a string is <a href="QValidator.html#State-enum">Acceptable</tt></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</tt></a> string, it is considered <a href="QValidator.html#State-enum">Intermediate</tt></a>. For example, &quot;&quot; and &quot;A&quot; are <a href="QValidator.html#State-enum">Intermediate</tt></a> for the regexp <b>[A-Z][0-9]</b> (whereas &quot;_&quot; would be <a href="QValidator.html#State-enum">Invalid</tt></a>).</p> <p>For a brief introduction to Qt's regexp engine, see <a href="%2E%2E/core/QRegExp.html"><tt>QRegExp</tt></a>.</p> <p>Example of use:</p> <pre><span class="comment"> // regexp: optional '-' followed by between 1 and 3 digits</span> QRegExp rx(&quot;-?\\d{1,3}&quot;); 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><span class="comment"> // integers 1 to 9999</span> QRegExp rx(&quot;[1-9]\\d{0,3}&quot;); <span class="comment"> // the validator treats the regexp as &quot;^[1-9]\\d{0,3}$&quot;</span> QRegExpValidator v(rx, 0); QString s; int pos = 0; s = &quot;0&quot;; v.validate(s, pos); <span class="comment">// returns Invalid</span> s = &quot;12345&quot;; v.validate(s, pos); <span class="comment">// returns Invalid</span> s = &quot;1&quot;; v.validate(s, pos); <span class="comment">// returns Acceptable</span> rx.setPattern(&quot;\\S+&quot;); <span class="comment">// one or more non-whitespace characters</span> v.setRegExp(rx); s = &quot;myfile.txt&quot;; v.validate(s, pos); <span class="comment">// Returns Acceptable</span> s = &quot;my file.txt&quot;; v.validate(s, 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.setPattern(&quot;[A-C]\\d{5}[W-Z]&quot;); v.setRegExp(rx); s = &quot;a12345Z&quot;; v.validate(s, pos); <span class="comment">// Returns Invalid</span> s = &quot;A12345Z&quot;; v.validate(s, pos); <span class="comment">// Returns Acceptable</span> s = &quot;B12&quot;; v.validate(s, pos); <span class="comment">// Returns Intermediate</span> <span class="comment"> // match most 'readme' files</span> rx.setPattern(&quot;read\\S?me(\.(txt|asc|1st))?&quot;); rx.setCaseSensitive(false); v.setRegExp(rx); s = &quot;readme&quot;; v.validate(s, pos); <span class="comment">// Returns Acceptable</span> s = &quot;README.1ST&quot;; v.validate(s, pos); <span class="comment">// Returns Acceptable</span> s = &quot;read me.txt&quot;; v.validate(s, pos); <span class="comment">// Returns Invalid</span> s = &quot;readm&quot;; v.validate(s, pos); <span class="comment">// Returns Intermediate</span></pre> @see <a href="%2E%2E/core/QRegExp.html"><tt>QRegExp</tt></a> @see <a href="QIntValidator.html"><tt>QIntValidator</tt></a> @see <a href="QDoubleValidator.html"><tt>QDoubleValidator</tt></a> @see Settings Editor Example</tt> */"> <method name="public QRegExpValidator(com.trolltech.qt.core.QObject parent)" doc="/** <p>Constructs a validator with a <tt>parent</tt> object that accepts any string (including an empty one) as valid.</p> */"/> <method name="public QRegExpValidator(com.trolltech.qt.core.QRegExp rx, com.trolltech.qt.core.QObject parent)" doc="/** <p>Constructs a validator with a <tt>parent</tt> object that accepts all strings that match the regular expression <tt>rx</tt>.</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> */"/> <method name="public final com.trolltech.qt.core.QRegExp regExp()" doc="/** <p>Returns the regular expression used for validation.</p> @see <a href="QRegExpValidator.html#setRegExp(com.trolltech.qt.core.QRegExp)"><tt>setRegExp</tt></a> */"/> <method name="public final void setRegExp(com.trolltech.qt.core.QRegExp rx)" doc="/** <p>Sets the regular expression used for validation to <tt>rx</tt>.</p> @see <a href="QRegExpValidator.html#regExp()"><tt>regExp</tt></a> */"/> <method name="public com.trolltech.qt.gui.QValidator.State validate(com.trolltech.qt.gui.QValidator.QValidationData input)" doc="/** <p>Equivalent to <a href="QRegExpValidator.html#validate(com.trolltech.qt.gui.QValidator.QValidationData)">validate</tt></a>(<tt>input</tt>, ). */"/> </class>