RegularExpressionValidator QML Type

Provides a string validator. More...

Import Statement: import QtQuick 2.15
Since: Qt 5.14
Instantiates: QRegularExpressionValidator

Properties

Detailed Description

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

Property Documentation

regularExpression : regularExpression

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 RegularExpressionValidator specified:

TextInput {
    id: hexNumber
    validator: RegularExpressionValidator { regularExpression: /[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})?$/

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.