IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

RegularExpressionValidator QML Type

Provides a string validator.

This type was introduced in Qt 5.14.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

RegularExpressionValidator QML Type

  • Import Statement: import QtQuick

  • Since:: Qt 5.14

  • Instantiates:: QRegularExpressionValidator

  • Group: RegularExpressionValidator is part of qtquick-text-utility, qtquick-text-validators

Detailed Description

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

See Also

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:

 
Sélectionnez
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:

     
    Sélectionnez
    /\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:

     
    Sélectionnez
    /(\d{1,3})([.,]\d{1,2})?$/

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+