[英]Can not validate input field using Angular.js
我在使用Angular.js驗證輸入字段時遇到問題。我需要輸入字段僅輸入數字( ie-0,1...
-0,1 ie-0,1...
),並且不允許使用任何字符。我在下面解釋我的代碼。
<div ng-class="{ 'myError': billdata.dis.$touched && billdata.dis.$invalid }">
<input type="text" name="dis" id="discount" class="form-control" placeholder="Add discount" ng-model="discount" ng-keypress="clearField('discount');" ng-keyup="setLatestSalePrice();" ng-pattern="/^[0-9]$/">
</div>
</div>
<div class="help-block" ng-messages="billdata.dis.$error" ng-if="billdata.dis.$touched">
<p ng-message="pattern" style="color:#F00;">This field needs only number(e.g-0,1..9).</p>
</div>
在這里輸入數字時,還會顯示驗證錯誤消息。請幫助我解決此問題。
幾處變化
form
標簽 name='form'
!form.$valid
/^(\\s*|\\d+)$/
以允許使用空字符串或數字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.