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