function checkform(obj)
	Dim i,sValid,a,b
	for each i in obj.elements
		if i.style.backgroundColor="#ff009f" then i.style.backgroundColor=""
		sValid=getProp(i,"valid")
		select case sValid
			case "notnull"
				if i.value="" then
					ocxAlert i,"item can not be empty"
					checkform=false
					exit function
				end if
			case "numeric"
				if i.value="" or not isnumeric(i.value) then
					ocxAlert i,"请输入正确的数字,如: 135 或 756.40"
					checkform=false
					exit function
				end if
			case "date"
				if i.value="" or not isdate(i.value) then
					ocxAlert i,"请输入正确日期,如: 2004-4-5"
					checkform=false
					exit function
				end if
			case "mail"
				if instr(i.value,".")<instr(i.value,"@") or len(i.value)<6  then
					ocxAlert i,"请输入正确的电子邮件地址，如：name@site.com"
					checkform=false
					exit function
				end if
			case "tel"
				if len(i.value)>20 or len(i.value)<8  then
					ocxAlert i,"请输入正确的电话号码，如：(+86)0123-12345678 或 13012345678"
					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)<a or len(i.value)>b then
							ocxAlert i,"此项目要求输入的字符个数在["&a&"]到["&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,"此项目要求输入的字符个数为["&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,"此项目要求输入的内容在["&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,"此项目要求输入大于等于["&a&"]并且小于等于["&b&"]的数字。"
							checkform=false
							exit function
						else
							if i.value*1<a*1 or i.value*1>b*1 then
								ocxAlert i,"此项目要求输入大于等于["&a&"]并且小于等于["&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="#ff009f"
end function
