我是一名设计师,对正则表达式不是很熟悉。在这个论坛的一些非常友善的海报的帮助下,我已经做出了很大的努力来做到这一点。下面名为 checkform 的脚本应该验证三个字段,“client”、“terms”和“AMOUNT”。这很简单,客户和条款是必填字段,而“AMOUNT”需要以正确的十进制格式输入,例如。27.00 欧元。它验证“客户”和“条款”但完全忽略“金额”?不检查它的任何东西。
任何帮助将不胜感激。
<form action=http://rcehholidaytrust.com/account/redirectoffresponsepage.php method=post onSubmit="return checkform()">
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Name </font></div></td>
<td><input type="text" name="name" size="48" /></td>
</tr>
<tr>
<td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Acc. No.</font></td>
<td><label for="client"></label>
<input name="CUST_NUM" type="text" id="client" size="48" /></td>
</tr>
<tr>
<td><div align="right">Payment €</div></td>
<td><label for="AMOUNT"></label>
<input name="AMOUNT" type="text" id="AMOUNT" size="47" /></td>
</tr>
<tr>
<td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Address</font></div></td>
<td><textarea name="address" wrap="virtual" cols="35" rows="5"></textarea></td>
</tr>
<tr>
<td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Telephone</font></div></td>
<td><input type="text" name="telephone" size="48" /></td>
</tr>
<tr>
<td><p align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Email</font></p></td>
<td><input type="text" name="email" size="48" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="checkbox" name="terms" id="terms" />
<label for="terms">Agree to terms and conditions</label></td>
</tr>
</table>
<p> </p>
<input type=submit value="Proceed to secure server">
</form>
<script>
function checkform()
{
var reg=/^[0-9]{1,6}\.[0-9]{2}$/;
var status=true;
if(!reg.test(document.getElementById('AMOUNT').value))
{
status=false;
}
if(document.getElementById('client').value=="" || document.getElementById('name').value=="")
{
status=false;
}
if(document.getElementById('terms').checked==false)
{
status=false;
}
if(status==false)
alert("Please check all fields");
return status;
}
</script>
</body>
</html>