<script type="text/javascript">
function check(name,reg,spaninfo,okinfo,errorinfo)
{
var flag;
var oNode = document.getElementsByName(name)[0];
var val = oNode.value;
var oSpanNode = document.getElementById(spaninfo);
if(reg.test(val))
{
oSpanNode.innerHTML = okinfo.fontcolor("green");
flag = true;
}
else
{
oSpanNode.innerHTML = errorinfo.fontcolor("red");
flag = false;
}
return flag;
}
//校验用户名
function checkUser()
{
var reg =/^\d{4}$/;
return check("user",reg,"user","用户名正确","用户名错误");
}
//校验密码
function checkPsw()
{
var reg=/^[a-z]{4}$/;
return check("psw",reg,"psw","密码正确","密码错误");
}
//确认密码
function checkRepsw()
{
var flag;
//获取密码框
var val_psw = document.getElementsByName("psw")[0].value;
//获取确认密码框
var val_repsw = document.getElementsByName("repsw")[0].value;
var ospan = document.getElementById("repsw");
if(val_repsw == val_psw)
{
ospan.innerHTML = "两次密码格式一致".fontcolor("green");
flag=true;
}
else
{
ospan.innerHTML = "两次密码格式不一致".fontcolor("red");
flag = false;
}
return flag;
}
//校验邮箱
function checkMail()
{
var reg =/^\w+@\w+(\.\w+)+$/;
return check("mail",reg,"mail","邮箱格式正确","邮箱格式错误");
}
function submitfrom()
{
var ofrom = document.getElementById("submit");
if(checkUser()&&checkPsw()&&checkRepsw()&&checkMail())
ofrom.submit();
}
function checkFrom()
{
if(checkUser()&&checkPsw()&&checkRepsw()&&checkMail())
return true;
else
return false;