2016-08-03 84 views
1

enter image description here我有一個「txtPhone」輸入濾波器不是強制性的,但只能接受電話號碼,所以:如果字段留空,如何不顯示glyphicon-ok?

<label class="control-label">Phone</label> 
<input type="text" id="txtPhone" class="form-control intonly" maxlength="12" placeholder="Phone" name="Phone"> 

引導驗證

Phone: { 
         validators: { 
          regexp: { 
           regexp: /^((091|\+91)?|\((091|\+91)?\)|(91)?|\(91\)|0)? ?[7-9][0-9]{9}$/, 
           message: 'The Indian Phone No must contain 10 digits' 
          }, 

         } 
        }, 

但是,當我點擊提交按鈕剔如圖文本框。

+0

'要求:TRUE'? –

+0

但它不是強制性的。 – Wenson

+0

那麼問題是什麼?如果該字段爲空,則該字段有效... –

回答

1

龍掙扎JesusGrace後,我找到了答案

Bootstrap Validation 

    Phone: { 
        enabled: false, 
        validators: { 
         regexp: { 
          regexp: /^((091|\+91)?|\((091|\+91)?\)|(91)?|\(91\)|0)? ?[7-9][0-9]{9}$/, 
          message: 'The Indian Phone No must contain 10 digits' 
         }, 

        } 
       }, 


     .on('keyup', '[name="Phone"]', function() { 
       var isEmpty = $(this).val() == ''; 
       $('#form1') 
         .formValidation('enableFieldValidators', 'Phone', !isEmpty); 
       // Revalidate the field when user start typing in the Phone field 
       if ($(this).val().length == 1) { 
        $('#form1').formValidation('validateField', 'Phone') 
       } 
      }) 
相關問題