RegularExpressionValidator QML Type
提供一个字符串验证器。更多...
| Import Statement: | import QtQuick |
| In C++: | QRegularExpressionValidator |
属性
- regularExpression : regularExpression
详细说明
RegularExpressionValidator 类型提供了一个验证器,该验证器将任何与指定正则表达式匹配的字符串视为有效。
另请参阅 IntValidator 、DoubleValidator 以及《验证输入文本》。
属性文档
regularExpression : regularExpression
该属性存储用于验证的正则表达式。
请注意,该属性应为符合 JS 语法的正则表达式,例如 /a/ 表示匹配字符串“a”的正则表达式。
默认情况下,此属性包含一个模式为.* 的正则表达式,该表达式可匹配任何字符串。
下面是一个指定了RegularExpressionValidator 的TextInput 对象示例:
TextInput {
id: hexNumber
validator: RegularExpressionValidator { regularExpression: /[0-9A-F]+/ }
}更多正则表达式的示例:
- 一个由逗号分隔、包含一到三个位置的数字列表:
/\d{1,3}(?:,\d{1,3})+$/ - 由小数点前最多 3 位数字和小数点后 1 至 2 位数字组成的金额:
/(\d{1,3})([.,]\d{1,2})?$/
© 2026 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.