如何验证邮编文本框不能输入字母
名为Validate.js的javascirpt文件
function checkData()
{
var zip = document.getElementById("Zip").value
if(/^[1-9]\d*$/.test(zip))
{
}
else
{
alert("You couldn't enter the letter!");
}
}
html端代码
<html>
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript" src="Validate.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<table>
<tr>
<td>
Zip Code
</td>
<td>
<asp:TextBox ID="Zip" runat="server" onblur="checkData()"></asp:TextBox>
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
function checkData()
{
var zip = document.getElementById("Zip").value
if(/^[1-9]\d*$/.test(zip))
{
}
else
{
alert("You couldn't enter the letter!");
}
}
html端代码
<html>
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript" src="Validate.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<table>
<tr>
<td>
Zip Code
</td>
<td>
<asp:TextBox ID="Zip" runat="server" onblur="checkData()"></asp:TextBox>
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>