diff --git a/dcc-network/qml/NetUtils.js b/dcc-network/qml/NetUtils.js index 9d74c2ec..7c732c9d 100644 --- a/dcc-network/qml/NetUtils.js +++ b/dcc-network/qml/NetUtils.js @@ -1,5 +1,5 @@ .pragma library -// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // SPDX-License-Identifier: GPL-3.0-or-later const VpnTypeEnum = Object.freeze({ "l2tp": 0x01, @@ -12,9 +12,13 @@ const VpnTypeEnum = Object.freeze({ }) // ip正则表达式 const ipRegExp = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))$/ +// ip编辑时宽松正则(仅允许数字和点) +const ipEditRegExp = /^[0-9.]*$/ const ipv6RegExp = /^(((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))))$/ // 子网掩码 const maskRegExp = /(254|252|248|240|224|192|128|0)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)/ +// 子网掩码编辑时宽松正则(仅允许数字和点) +const maskEditRegExp = /^[0-9.]*$/ // MAC正则表达式 const macRegExp = /([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/ diff --git a/dcc-network/qml/SectionIPv4.qml b/dcc-network/qml/SectionIPv4.qml index ec390032..2d787ed2 100644 --- a/dcc-network/qml/SectionIPv4.qml +++ b/dcc-network/qml/SectionIPv4.qml @@ -340,7 +340,7 @@ DccObject { page: D.LineEdit { text: addressData.length > index ? addressData[index][0] : "0.0.0.0" validator: RegularExpressionValidator { - regularExpression: NetUtils.ipRegExp + regularExpression: NetUtils.ipEditRegExp } onTextChanged: { if (showAlert) { @@ -372,7 +372,7 @@ DccObject { page: D.LineEdit { text: addressData.length > index ? addressData[index][1] : "255.255.255.0" validator: RegularExpressionValidator { - regularExpression: NetUtils.maskRegExp + regularExpression: NetUtils.maskEditRegExp } onTextChanged: { if (showAlert) { @@ -404,7 +404,7 @@ DccObject { enabled: index === 0 text: index === 0 && addressData.length > index ? addressData[index][2] : "" validator: RegularExpressionValidator { - regularExpression: NetUtils.ipRegExp + regularExpression: NetUtils.ipEditRegExp } onTextChanged: { if (showAlert) {