日期:2014-05-20 浏览次数:20722 次
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> <title>验证Email和数字</title> </head> <script language="JavaScript"> function add(){ var y=/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/; var yj=frm.email.value; var up = frm.unitPrice.value; var p =/^[1-9]\d*$/; if(frm.goodsName.value=="") { alert("货物的名字不能为空!!") } else if(frm.unitPrice.value=="") { alert("单价不能为空!!") } else if(!p.test(up)) { alert("货物单价只能为数字!!") } else if(!y.test(yj)) { alert("邮箱地址不对!!") } else{ frm.action="goods.do?action=adm"; frm.submit(); alert("验证成功") } } </script> <body> <br> <center> <form name="frm" method="post"> <TABLE cellSpacing=0 cellPadding=0 width=450 bgColor="#C6D3FF" border=0> <TBODY> <TR> <TD style="FONT-WEIGHT: bolder; FONT-SIZE: small; COLOR: white" align=middle bgColor=#4682b4 colSpan=2>验证Email和数字</TD></TR> <TR bgColor="#C6D3FF"> <TD style="WIDTH: 143px"><SPAN id=Label1>货物名字</SPAN></TD> <td><input type="text" name="goodsName"></td> </TR> <TR bgColor="#C6D3FF"> <TD style="WIDTH: 143px"><SPAN id=Label1>邮箱地址</SPAN></TD> <td><input type="text" name="email"></td> </TR> <TR bgColor="#C6D3FF"> <TD style="WIDTH: 143px"><SPAN id=Label1>货物单价</SPAN></TD> <td><input type="text" name="unitPrice"></td> </TR> <TR><td><br></td></TR> <TR> <td></td> <TD align="left"> <p><a href="javascript:add()"><font size=3>验证</font></a></p> </td> </TR> </TBODY> </TABLE> </form></center> </body> </html>
------解决方案--------------------
正则表达式