2015-11-17 47 views
1

我試圖對基本引導程序HTML 5的表單使用1000hz驗證程序,並且我沒有使用任何自定義查詢,但我不知道它。我使用了接受10位電話號碼的文本字段。我修改了我的代碼,如1000hz github bootstrap驗證器所示。但是,當我開始鍵入一些數字時,它在框的結尾處顯示一個刻度標記,並且當我切換到下一個元素時,它不會根據驗證HTML 5顯示ax標記。我只想在用戶輸入10位數字。如果恢復並刪除幾位數字,它應該顯示x標記,直到他輸入10位數字。請幫忙謝謝。1000hz自舉驗證程序

<div class="form-group textareawidth has-feedback"> 
    <label for="mobile">Principal's Mobile number </label> 
    <input type ="text" minlength = "10" maxlength="10" class="form-control" placeholder="Enter mobile number" name = "hmmobile" id="mobile" data-error="Phone number is invalid" required> 
    <span class="glyphicon form-control-feedback" aria-hidden="true"></span> 
    <span class="help-block with-errors">Please enter 10 digit number</span> 
</div> 

另一點,一個用戶指出我使用1000hz,其中包括validator.js。但它沒有工作,我需要包括更多的文件。然後在網站中提供的示例工作。我是正確的,因爲我是一個新手。

<script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.9.0/validator.min.js"></script> 
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script> 
<script src="{{ site.cdn_bootstrap_js }}"></script> 
<script src="dist/validator.min.js"></script> 
<script src="http://platform.twitter.com/widgets.js"></script> 
<script src="assets/js/application.js"></script> 

這些是包含的文件。

回答

0

必須使用數據屬性data-minlength檢查和驗證在輸入字符的長度Check Reference Here

data-minlength = "10"

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.9.0/validator.min.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" /> 
 
<form data-toggle="validator" role="form"> 
 
    <div class="form-group textareawidth has-feedback"> 
 
     <label for="mobile">Principal's Mobile number</label> 
 
     <input type="text" pattern="^[0-9]{1,}$" data-minlength="10" maxlength="10" class="form-control" placeholder="Enter mobile number" name="hmmobile" id="mobile" data-error="Phone number is invalid" required> <span class="glyphicon form-control-feedback" aria-hidden="true"></span> 
 
<span class="help-block with-errors">Please enter 10 digit number</span> 
 
    </div> 
 
</form>

的SideNote替換minlength = "10":你有1000hz-bootstrap-validator/0.9.0/validator.min.js以上jquery-1.10.2.min.js,然後再次<script src="dist/validator.min.js"></script>

不能有validator.min.js LIB兩次,以去除其中第一個是前jquery-1.10.2.min.js

+0

它甚至模式^ [0-9] {10} $受理後10個字符,並說OK。對於前aaaaaaaaaa是好的 –

+0

我非常感謝你的答案。謝謝 –

+0

更新了答案和代碼片段,添加了'pattern =「^ [0-9] {1,} $」'並沒有說'aaaaaaaaaa'確定,它表示它是無效的 – Shehary