时间:2021-05-17 python教程 查看: 899
自己编写的用于对lineEdit编辑框输入的子网,例如:192.168.60.1/24字符串校验是否合规。
# 限制lineEdit编辑框只能输入./字符和数字
reg = QRegExp('[0-9./]+$')
validator = QRegExpValidator(self)
validator.setRegExp(reg)
self.lineEditSubNet.setValidator(validator)
def SubnetVerification(self, strTempSubNet):
"""
对输入的子网字符串进行校验
"""
# 对输入的交换机子网地址及子网掩码格式进行校验
if strTempSubNet.count('/') == 1:
pass
else:
# 警告信息框
win32api.MessageBox(0, "请输入正确的子网,例:192.168.60.1/24", "温馨提示", win32con.MB_ICONWARNING)
return False
strListNet = strTempSubNet.split('/')
if strListNet[0] != '' and strListNet[1] != '':
pass
else:
# 警告信息框
win32api.MessageBox(0, "请输入正确的子网,例:192.168.60.1/24", "温馨提示", win32con.MB_ICONWARNING)
return False
self.strIP = strListNet[0]
self.strSubMaskNum = strListNet[1]
# print(self.strIP)
# print(self.strSubMaskNum)
if 1 <= int(self.strSubMaskNum, 10) <= 32:
pass
else:
# 警告信息框
win32api.MessageBox(0, "请输入正确的子网,例:192.168.60.1/24", "温馨提示", win32con.MB_ICONWARNING)
return False
# 对输入的交换机子网地址进行校验
# 判断是否符合IP地址中有3个.
if self.strIP.count('.') == 3:
pass
else:
# 警告信息框
win32api.MessageBox(0, "请输入正确的子网,例:192.168.60.1/24", "温馨提示", win32con.MB_ICONWARNING)
return False
strList = self.strIP.split(".")
# print(strList)
if strList[0] != '' and strList[1] != '' and strList[2] != '' and strList[3] != '':
pass
else:
# 警告信息框
win32api.MessageBox(0, "请输入正确的子网,例:192.168.60.1/24", "温馨提示", win32con.MB_ICONWARNING)
return False
nList = list(map(int, strList))
if 0 <= nList[0] <= 255 and 0 <= nList[1] <= 255 and 0 <= nList[2] <= 255 and 0 <= nList[3] <= 255:
pass
else:
# 警告信息框
win32api.MessageBox(0, "请输入正确的子网,例:192.168.60.1/24", "温馨提示", win32con.MB_ICONWARNING)
return False
return True
到此这篇关于PyQt5 QLineEdit输入的子网字符串校验QRegExp实现的文章就介绍到这了,更多相关PyQt5 QLineEdit校验QRegExp内容请搜索python博客以前的文章或继续浏览下面的相关文章希望大家以后多多支持python博客!