JS验证
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<Script>
var RegType=
{
EMail:/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,
QQ:/^[0-9]{5,9}$/,
}
function IsOk(value, regExpress)
{
var v=value;
var reg=regExpress;
if(RegType[reg] == null)
{
return false;
}
return (v.match(RegType[reg]) == null)? false:true;
}
function CheckForm()
{
var formID='form1';
var objCol=document.getElementById(formID);
for(var i=0;i<objCol.elements.length;i++)
{
var vt = objCol[i].getAttribute("vt");
if(!vt)
{
continue;
}
if(!IsOk(objCol[i].value, vt))
{
document.getElementById(objCol[i].msgID).innerHTML = "必须是" + vt;
}
else
{
document.getElementById(objCol[i].msgID).innerHTML = "";
}
}
}
</Script>
</HEAD>
<BODY>
<form id=form1>
<input id=txtEMail msgID=msg1 vt='EMail'/>
<span id=msg1></span>
<input id=txtQQ msgID=msg2 vt=QQ>
<span id=msg2></span>
<input type=button onclick="return CheckForm()" value=提交>
</form>
</BODY>
</HTML>