我在eclipse下使用JQuery-mobile。我有一個帶有兩個文本字段的表單,我希望表單中的第一個文本字段只能接受數字,所以如果輸入是字符或文本,甚至是空的,我想要出現一個錯誤。至於驗證去,我使用jquery validVal。我已經包括了我的代碼`JQuery-mobile驗證!
<form id="ccform" method = "post">
<table>
<tr>
<td><label for="cc">Card Number</label></td>
<td><input name = "ccc" class="required" type = "text" id = "cc" maxlength="23" " ></td>
</tr>
<tr>
<td>Card Holder Name</td>
<td><input class="required" type = "text"></td>
</tr>
</table>
</form>
也:
<script>
$("#ccform").validVal({
customValidaton:{
"cc": function ($field){
var myexpr =/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/
if(myexpr.test($field.val())) {return true;}
else{return false;}
}
}
});
</script>
`
,但我沒有得到任何結果,沒有什麼......所以任何幫助,將不勝感激。
我剛剛更新了我的代碼和問題。它仍然不起作用。 –