電話の市外局番を収集する登録フォームにテキストボックスがあります-私の賢い自己は、私の顧客が3桁の市外局番の代わりに5桁の郵便番号を入力するのはそれほど素晴らしいとは思わなかったので、今度は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()
}
}
}