function checkform(obj) Dim i,sValid,a,b for each i in obj.elements if i.style.backgroundColor="#ffd0d0" then i.style.backgroundColor="" sValid=getProp(i,"valid") select case sValid case "notnull" if i.value="" then ocxAlert i,"the item can not be empty" checkform=false exit function end if case "numeric" if i.value="" or not isnumeric(i.value) then ocxAlert i,"input number please" checkform=false exit function end if case "mail" if instr(i.value,".")20 or len(i.value)<8 then ocxAlert i,"invalid phone " checkform=false exit function end if case else '字符个数: len=a,b 或 len=a if lcase(left(sValid,4))="len=" then sValid=replace(sValid,"len=","") if instr(sValid,",") then a=trim(split(sValid,",")(0)) b=trim(split(sValid,",")(1)) if isnumeric(a) then a=cint(a) if isnumeric(b) then b=cint(b) if len(i.value)b then ocxAlert i,"string length must ["&a&"] to ["&b&"]" checkform=false exit function end if else a=trim(sValid) if isnumeric(a) then a=cint(a) if len(i.value)<>a then ocxAlert i,"string length must be ["&a&"]" checkform=false exit function end if end if end if '输入的有效范围: range=a,b 或 range=(a,b,c,d,....) if lcase(left(sValid,6))="range=" then sValid=replace(sValid,"range=","") if cbool(instr(sValid,"(")) and cbool(instr(sValid,")")) then sValid=replace(sValid,"(","") sValid=replace(sValid,")","") sValid=","&sValid&"," if not cbool(instr(sValid,","&i.value&",")) then sValid=left(sValid,len(sValid)-1) sValid=right(sValid,len(sValid)-1) ocxAlert i,"item must be range in ["&sValid&"]" checkform=false exit function end if else a=trim(split(sValid,",")(0)) b=trim(split(sValid,",")(1)) if not isnumeric(a) then exit function if not isnumeric(b) then exit function if not isnumeric(i.value) then ocxAlert i,"item must be >=["&a&"] and <=["&b&"]" checkform=false exit function else if i.value*1b*1 then ocxAlert i,"item must be >=["&a&"] and <=["&b&"]" checkform=false exit function end if end if end if end if end select next end function function getProp(obj,str) on error resume next if str="valid" then getProp=obj.valid if str="msg" then getProp=obj.msg end function function ocxAlert(i,strErr) if getProp(i,"msg")="" then msgbox strErr,64,"Warn" else msgbox getProp(i,"msg"),64,"Warn" end if on error resume next i.focus() i.select() i.style.backgroundColor="#ffd0d0" end function