簡體   English   中英

如何使用Angular.js僅禁止字符進入輸入字段

[英]How to disallow only characters into input field using Angular.js

我不需要只允許字符到我的輸入字段,並希望使用Angular.js檢查驗證。 我的代碼如下。

<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right oditek-form" style="width:180px">Longitude:</span>
<div ng-class="{ 'myError': billdata.longitude.$touched && billdata.longitude.$invalid }">
<input type="text" name="longitude" id="longitude" class="form-control oditek-form" placeholder="Add Longitude coordinate" ng-model="longitude"  ng-pattern="/^[0-9]+([,.][0-9]+)?$/" ng-keypress="clearField('businessno');" >
</div>
<span class="input-group-btn">
<a ui-sref="dashboard.customer.view" class="btn btn-success" style="height:30px;" title="Click Here" ng-click="getLongValue();"><i class="fa fa-map-marker" aria-hidden="true"></i></a>
 </span>
</div>

在上面的代碼中,我還將一些正則表達式設置為ng-pattern但它不允許使用-12.345,+2.345 etc 在這里我需要這個字段只允許數字('ie-1,2 ... 9'),特殊字符( only +, -, . etc )。

ng-pattern這種模式應匹配:

ng-pattern="/^[0-9,\.\-\+]+$/"

可能是ng-pattern =“/ [0-9,\\ W] / g”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM