QML输入框同样能用正则表达式,在输入ip地址时使用正则来判断输入的正确性
TextField {
id: textfield_operation_ip1
x: 492
y: 120
width: 269
height: 61
text: ""
visible: true
placeholderText: qsTr("请输入IP地址")
font.pixelSize: 25
focus:true
validator: RegExpValidator{regExp:/(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/}
// style: textfied_style
}
转载于:https://blog.51cto.com/landm/2404621