我在登记表上有一个收集电话区号的文本框——我聪明的自己认为我的客户不会那么好输入 5 位数的邮政编码而不是 3 位数的区号,所以现在我需要制作一个 jquery或用于验证条目的javascript函数是###,###,###,###,###...格式 他们可以输入的区号数量没有限制。问题是我不知道代码应该如何运行 - 我的文本框有任何想法
<input type="text" id="acode" name="acode" />
我很感激
完成的代码
HTML
<label for="acode">Enter area codes separated by commas (757,804,252,###):</label>
<input type="text" id="acode" name="acode" onblur="valarea(this.form)"/>
Javascript
<script>
function valarea(form)
{
inputvalue =form.acode.value;
var regexp = /^\d{3}(?:,\d{3})*$/;
if (inputvalue != "")
{
if (regexp.test(inputvalue)) {
//nothing happens
} else {
alert('You have entered an invalid value, you should have listed 3 digit telephone area codes for the areas you are interested in shopping separated by commas (757,804,252,###) Please Correct the problem before continuing')
form.acode.focus()
}
}
}