你好我在編寫我的表單,我已經驗證了它與jQuery和PHP,但我需要在我的手機輸入只有數字才能使用,必須出現最少6個數字。在這個jQuery代碼結構:在特定的代碼結構中驗證jQuery中的iput
if ($('input[name="phone"]').val().length ===0){
erros = 1;
}
else {
$('input[name="phone"]').removeClass('warning');
}
這裏的手機輸入代碼:
<label class="label">Phone Number</label>
<label class="input">
<i class="icon-append fa fa-phone"></i>
<input type="text" name="phone" id="phone" >
</label>
如何立足於我的需求了jQuery驗證?在此先感謝
我剛剛更新了我的劇本和我做了它在某種程度上驗證只輸入數字,但現在到10號在這裏的電話輸入框typet代碼我不能盼着去:
var phoneVal=$('input[name="phone"]').val();
phoneantigo = phoneVal.toString();
var phoneReg = /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})$/;
if ($('input[name="phone"]').val().length === 0) {
erros = 1;}
else if(!phoneReg.test(phoneVal)) {
$('input[name="phone"]').val('');
erros = 1;
}
else {
$('input[name="phone"]').removeClass('warning');}//end of test
也許這有助於:http://stackoverflow.com/questions/19840301/jquery-to-validate-phone-number – 2014-10-06 15:06:00
我現在檢查,謝謝@Daniel – 2014-10-06 15:25:03