求一个数据窗口的某一个字段不为空和电话的验证的示例,要有光标移开就要有提示!谢谢!
------解决方案--------------------
在dw的itemchanged事件中写:
if isnull(dwo) or row < 1 then return
if dwo.name = '不能为空的字段的字段名' then
if data = '' then
messagebox('提示', '字段不能为空!')
return
end if
elseif dwo.name = '电话字段' then
//电话号码只能包括数字和-,固话以0开始,手机以1开始
if not f_is_telnum(data) then
messagebox('提示', '电话号码格式不正确')
end if
end if
------解决方案--------------------
boolean f_is_telnum(string as) 可以这么写:
int li
li = pos(as, '-')
if li <> lastpos(as, '-') then return false //包含1个以上的- ,则有误
if li > 0 then as = left(as, li - 1) + mid(as, li + 1) //去换-
if not isnumber(as) then return false //包含数字以外的字符,则有误
if len(as) > 12 then return false //长度过长,则有误
choose case left(as, 1)
case '1' //手机
case '0' //固化
case else
return false //错误
end choose
return true
------解决方案--------------------
if dwo.name = '不能为空的字段的字段名' then
'不能为空的字段的字段名' 就是你的字段名.
------解决方案--------------------
在数据窗口设计界面的Column Specification 面板中,找到需要设置不能为空的列,
然后在该列的Validation Expression中写:gettext() <> ''
在该列的Validation Message中写:'该字段不能为空!'
------解决方案--------------------
在itemfocuschanged事件中加上
if gettext() = '' then settext('')
------解决方案--------------------
引用:
在数据窗口设计界面的Column Specification 面板中,找到需要设置不能为空的列,
然后在该列的Validation Expression中写:gettext() <> ''
在该列的Validation Message中写:'该字段不能为空!'
yyoinge 8楼和9楼 的方法都可以的。
8楼方法请参考下图位置加入8楼的判断。
[img=http://hi.csdn.net/space-167635-do-album-picid-998760.html][/img]
------解决方案--------------------
/img/2012/12/23/2050376140.jpg[
img=/img/2012/12/23/2050376140.jpg][/img]
------解决方案--------------------
