<!--#INCLUDE FILE="encrypt.asp" -->
<!--#INCLUDE FILE="validate.asp" -->
<%
function chkinput()

	dim ErrMsg,FoundErr
	dim biryear,birmonth,birday

	If chkpost=false then
		ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从同学录外部提交信息。"
		call top(1,1)
		call error("Critical",errmsg)
		chkinput=false
		exit function
	end If

	userid=trim(request.form("userid"))

	If userid="" or strlength(userid)<4 or strlength(userid)>12 then
		errmsg=errmsg+"<br>"+"<li>请输入用户名（4-12个字符）！"
		founderr=true
	ElseIf isValidstring(userid)<>"" then
		If isValidstring(userid)=" " then invld="空格" Else invld=isValidstring(userid)
		errmsg=errmsg+"<br>"+"<li>用户名中含有非法字符&nbsp;<font color=#cc0000>"&invld&"</font>&nbsp;。"
		founderr=true
	Else
		set rs=conn.execute("Select * from student where userid='"&userid&"'")

		If not (rs.EOF and rs.bof) then
			Errmsg=Errmsg+"<br>"+"<li>用户名已存在!"
			founderr=true
		end If
		set rs=nothing
	end If

	If founderr=true then
		call top(1,1)
		call error("Information",errmsg)
		chkinput=false
		exit function
	end If

	realname=trim(request.form("realname"))

	If realname="" or strLength(realname)<4 or strLength(realname)>8 then
		errmsg=errmsg+"<br>"+"<li>真实姓名输入有误。"
		founderr=true
	ElseIf not isChinese(realname) then
		errmsg=errmsg+"<br>"+"<li>真实姓名应为汉字。"
		founderr=true
	end If

	userpwd1=request.form("userpwd1")
	userpwd=request.form("userpwd2")
	If userpwd<>userpwd1 then 
		errmsg=errmsg+"<br>"+"<li>您两次输入的密码不一致!"
		founderr=true
	end If

	If userpwd1="" or len(userpwd1)<6 or len(userpwd1)>12 then
		errmsg=errmsg+"<br>"+"<li>请确认输入了密码（6-12个字符）！"
		founderr=true
	ElseIf isValidstring(userpwd1)<>"" then
		If isValidstring(userpwd1)=" " then invld="空格" Else invld=isValidstring(userpwd1)
		errmsg=errmsg+"<br>"+"<li>密码中含有非法字符&nbsp;<font color=#cc0000>"&invld&"</font>&nbsp;。"
		founderr=true
	ElseIf userpwd1=userid then
		errmsg=errmsg+"<br>"+"<li>密码不能和用户名相同！"
		founderr=true
	end If

	question=trim(request.form("question"))

	answer=trim(request.form("answer"))


	If question="" and answer<>"" or question<>"" and answer="" then
		errmsg=errmsg+"<br>"+"<li>取回密码时的提示问题和答案必需同时输入，如果不想使用此功能请留空!"
		founderr=true
	ElseIf answer<>"" and question<>"" then

		If strlength(question)<6 or strlength(question)>20 then
			errmsg=errmsg+"<br>"+"<li>取回密码提示问题不能少于6个字符或多余20个字符!"
			founderr=true
		ElseIf isValidstring(question)<>"" then
			If isValidstring(question)=" " then invld="空格" Else invld=isValidstring(question)
			errmsg=errmsg+"<br>"+"<li>密码提示问题中含有非法字符&nbsp;<font color=#cc0000>"&invld&"</font>&nbsp;。"
			founderr=true
		end If

		If strlength(answer)<6 or strlength(answer)>20 then
			errmsg=errmsg+"<br>"+"<li>取回密码答案不能少于6个字符或多余20个字符!"
			founderr=true
		ElseIf isValidstring(answer)<>"" then
			If isValidstring(answer)=" " then invld="空格" Else invld=isValidstring(answer)
			errmsg=errmsg+"<br>"+"<li>取回密码答案中含有非法字符&nbsp;<font color=#cc0000>"&invld&"</font>&nbsp;。"
			founderr=true
		end If

		If question=answer then
			errmsg=errmsg+"<br>"+"<li>取回密码答案不能和提示问题相同!"
			founderr=true
		ElseIf answer=userid then
			errmsg=errmsg+"<br>"+"<li>取回密码答案不能和用户名相同!"
			founderr=true
		end If

	end If


	biryear=request.Form("year")
	If len(biryear)<>4 or not isInteger(biryear) then
		ErrMsg=ErrMsg+"<br>"+"<li>生日年份应为四位数字!"
		FoundErr=true
	Else
		biryear=cint(biryear)
		If biryear>cint(year(date)) or biryear<(cint(year(date))-60) then
			ErrMsg=ErrMsg+"<br>"+"<li>请输入正确的用户出生年份！"
			FoundErr=true
		End If
	End If

	birmonth=request.form("month")
	birday=request.form("day")
	birthday=biryear&"-"&birmonth&"-"&birday
	if not isDate(birthday) then
		errmsg=errmsg+"<br>"+"<li>生日输入有误！"
		founderr=true
	else
		birthday=cdate(birthday)
	end if


	email=trim(request.form("email"))
	If email="" then
		errmsg=errmsg+"<br>"+"<li>电子邮件不能为空。"
		founderr=true
	ElseIf not isValidEmail(email) then
		errmsg=errmsg+"<br>"+"<li>电子邮件输入有误！"
		founderr=true
	end If

	homepage=trim(request.form("homepage"))
	If homepage<>"" and homepage<>"http://" and left(homepage,7)<>"http://" then
		homepage="http://"&homepage
	end If

	oicq=trim(request.form("oicq"))
	If oicq<>"" and (len(oicq)<4 or len(oicq)>10 or not isinteger(oicq)) then
		errmsg=errmsg+"<br>"+"<li>OICQ输入有误！"
		founderr=true
	end If

	msn=trim(request.form("msn"))
	If msn<>"" and not isValidEmail(msn) then
		errmsg=errmsg+"<br>"+"<li>MSN号码输入有误！"
		founderr=true
	end If

	telephone=trim(request.form("telephone"))
	If telephone<>"" and not IsValidTel(telephone) then
		errmsg=errmsg+"<br>"+"<li>电话号码输入错误"
		founderr=true
	end If

	mobilephone=trim(request.form("mobilephone"))
	if mobilephone<>"" and (len(mobilephone)<>11 or not isinteger(mobilephone) or left(mobilephone,2)<>"13") then
		errmsg=errmsg+"<br>"+"<li>移动电话输入错误"
		founderr=true
	end If

	zipcode=trim(request.form("zipcode"))
	address=trim(request.form("address"))
	If address<>"" and zipcode="" then
		errmsg=errmsg+"<br>"+"<li>请输入邮政编码"
		founderr=true
	end If

	If zipcode<>"" and (len(zipcode)<>6 or not isinteger(zipcode)) then
		errmsg=errmsg+"<br>"+"<li>邮政编码输入错误"
		founderr=true
	end If

	maxim=request.form("maxim")
	If strlength(maxim)>200 then
		ErrMsg=ErrMsg+"<br>"+"<li>人生格言不能大于200个字符。"
		FoundErr=true
	else
		mline=split(maxim,vbCrlf)
		if ubound(mline)>4 then
			ErrMsg=ErrMsg+"<br>"+"<li>人生格言不能多于5行。"
			FoundErr=true
		end if
	End If

	If founderr=true then
		call top(1,1)
		call error("Information",errmsg)
		chkinput=false
	Else
		userpwd=md5(userpwd)
		if answer<>"" then 
			answer=md5(answer)
		end if
		chkinput=true
	end If

end function
%>