35 lines
885 B
QML
35 lines
885 B
QML
import QtQuick
|
|
import QtQuick.Controls
|
|
import QtQuick.Layouts
|
|
|
|
Column {
|
|
id: root
|
|
property alias text: input.text
|
|
property bool valid: false
|
|
TextField {
|
|
height: 36
|
|
width: 350
|
|
id: input
|
|
|
|
onTextChanged: {
|
|
valid = validateIp(text);
|
|
if(!valid){
|
|
hint.text="参数配置无效"
|
|
} else {
|
|
hint.text=""
|
|
}
|
|
}
|
|
}
|
|
Text {
|
|
id: hint
|
|
color: "red"
|
|
font.pixelSize: 12
|
|
}
|
|
|
|
function validateIp(ip) {
|
|
// Regular expression for validating IP address
|
|
var regex = /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/;
|
|
return regex.test(ip);
|
|
}
|
|
}
|