javascript asp教程第五课--合二为一(2)
<%@LANGUAGE="JavaScript"%>
<%
function checkMyZip(zipCode)
{
var myRegularExpression=/(^\d{5}$)|(^\d{5}-\d{4}$)/
if (myRegularExpression.test(zipCode) == true)
{
return nothingIsWrong();
}
else
{
return somethingIsWrong();
}
}
function nothingIsWrong()
{
//Do nothing
return true
}
function somethingIsWrong()
{
return false;
}
var zipCode=new String(Request.Form("zipCodeText"))
if (checkMyZip(zipCode)==true)
{
Response.Write("<HTML>\r")
Response.Write("The zip code you provided... ")
Response.Write("<FONT COLOR=\"RED\">")
Response.Write(zipCode + "</FONT> is good.\r")
Response.Write("</HTML>\r")
}
else
{
Response.Write("<HTML>\r")
Response.Write("The zip code you provided... ")
Response.Write("<FONT COLOR=\"RED\">")
Response.Write(zipCode + "</FONT> has a problem.\r")
Response.Write("</HTML>\r")
}
%>
这并不是最完美的列子,但是它包含了我们所要讲授的要点。客户端和服务器端严正数据的函数是完全一样的。支持函数是一样的饿,但是变化确是明显的。仅仅是个玩笑,让我们来看看下面的脚本。它并没有客户端验证。
复制代码 代码如下:
<%@LANGUAGE="JavaScript"%>
<%
//No ASP Here, just a regular HTML Page
%>
<HTML>
<STRONG>Type a zip code (with no client side validation)
into the box submit it.</STRONG>
<FORM NAME="zipCodeForm" ACTION="script05a.asp" METHOD="Post">
<INPUT TYPE="Text" NAME="zipCodeText"><BR>
内容版权声明:除非注明,否则皆为本站原创文章。