请帮我编写IP地址的datawindow编辑掩码。目前我这样做
###.###.###.###
但它也可以允许300.300.300.300
,并且有效的IP地址只允许最大255.255.255.255
。请指导我。感谢
答案 0 :(得分:0)
你不能。
您必须使用pbm_keydown
或pbm_downkey
作为事件ID创建用户事件,并编写脚本以阻止允许击键。返回值允许您拒绝该密钥。
答案 1 :(得分:0)
编辑蒙版不验证输入,只是格式化它。您可能最好使用itemchanged事件来验证数据。
答案 2 :(得分:0)
你的编辑面具没问题, 如果我是你,我将在数据窗口中定义4个数字列 如果你想要验证,你需要在itemchanged事件中编码:
ls_colname = dw_1.GetcolumnName()
Choose Case ls_colname
Case "subnet_msk_1"
if Integer(dw_1.getText()) > 255
MessageBox("Warning", "Incorrect Input, subnet mask value should not be > 255")
/*this will not let the datawindow accept the invalid input*/
return 1
end if
Case "subnet_msk_2"
/*do the same*/
Case "subnet_msk_3"
/*do the same*/
Case "subnet_msk_4"
/*do the same*/
/*write your logic here*/
End Choose
如果你只想使用1个字符串cloumn,我相信你需要使用mid()函数,只需在PB中按F1,你就可以找到例子,在你的情况下:
ls_colname = dw_1.GetcolumnName()
Choose Case ls_colname
Case "subnet_msk"
if Mid(dw_1.getText(), 1, 4) > 255 OR Mid(dw_1.getText(), 4, 8) > 255 /*etc..*/
/*your logic here*/
end if
答案 3 :(得分:0)
您可以使用Match功能在用户输入后验证IP地址:
int i, j
int matchedCount
boolean isValid
String patterns[] = {"^25[0-5]$", "^2[0-4][0-9]$", "^[01]?[0-9][0-9]?$"}
string ip[] = {"162","168","1","1"} // test for success
//string ip[] = {"162","168","256","101"} // test for fail
for i = 1 to 4
for j = 1 to 3
if match(ip[i], patterns[j]) then matchedCount++
next
next
isValid = (matchedCount = 4)
未优化,但紧凑