W3cubDocs

/Qt 5.15

RegExpValidator QML Type

Provides a string validator. More...

Import Statement: import QtQuick 2.15
Instantiates: QRegExpValidator

Properties

Detailed Description

The RegExpValidator type provides a validator, which counts as valid any string which matches a specified regular expression.

RegExpValidator is deprecated since it is based on the deprecated QRegExp. Use RegularExpressionValidator instead.

Property Documentation

regExp : regExp

This property holds the regular expression used for validation.

Note that this property should be a regular expression in JS syntax, e.g /a/ for the regular expression matching "a".

By default, this property contains a regular expression with the pattern .* that matches any string.

Below you can find an example of a TextInput object with a RegExpValidator specified:

TextInput {
    id: hexNumber
    validator: RegExpValidator { regExp: /[0-9A-F]+/ }
}

Some more examples of regular expressions:

  • A list of numbers with one to three positions separated by a comma:
    /\d{1,3}(?:,\d{1,3})+$/
  • An amount consisting of up to 3 numbers before the decimal point, and 1 to 2 after the decimal point:
    /(\d{1,3})([.,]\d{1,2})?$/

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5.15/qml-qtquick-regexpvalidator.html