求一个数据窗口的某一个字段不为空和电话的验证的示例,要有光标移开就要有提示!谢谢!
------解决方案--------------------
- C/C++ code
在dw的itemchanged事件中写:if isnull(dwo) or row < 1 then returnif dwo.name = '不能为空的字段的字段名' then if data = '' then messagebox('提示', '字段不能为空!') return end ifelseif dwo.name = '电话字段' then //电话号码只能包括数字和-,固话以0开始,手机以1开始 if not f_is_telnum(data) then messagebox('提示', '电话号码格式不正确') end if end if
------解决方案--------------------
- C/C++ code
boolean f_is_telnum(string as) 可以这么写:int lili = 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 choosereturn true
------解决方案--------------------
if dwo.name = '不能为空的字段的字段名' then
'不能为空的字段的字段名' 就是你的字段名.
------解决方案--------------------
在数据窗口设计界面的Column Specification 面板中,找到需要设置不能为空的列,
然后在该列的Validation Expression中写:gettext() <> ''
在该列的Validation Message中写:'该字段不能为空!'
------解决方案--------------------
在itemfocuschanged事件中加上
if gettext() = '' then settext('')
------解决方案--------------------
引用:
在数据窗口设计界面的Column Specification 面板中,找到需要设置不能为空的列,
然后在该列的Validation Expression中写:gettext() <> ''
在该列的Validation Message中写:'该字段不能为空!'
------解决方案--------------------
http://hi.csdn.net/attachment/201112/5/167635_1323062198B31E.jpg[
img=http://hi.csdn.net/attachment/201112/5/167635_1323062198B31E.jpg][/img]
------解决方案--------------------