如何在离子1中仅允许一个小数点输入类型编号 [英] How to allow only one decimal point for input of type number in ionic 1
本文介绍了如何在离子1中仅允许一个小数点输入类型编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用类型编号的输入,它允许多个小数点,所以我尝试使用正则表达式不允许超过一个小数点,但即使使用正则表达式我面临相同的问题,任何人都可以告诉我如何在ionic1中输入类型编号只允许一个小数点
Html:
<输入stopccp focus-me class =inputContainer trade_inputtype =numbername =ng-model =vm.total_amount [$ index]ng-change =vm.onTotalCost() limit-char limit =5ng-keyup =vm.decimalcheck(vm.total_amount [$ index])>
函数中的正则表达式:
function decimalcheck(element){
$ log.log('decimalcheck got called',element);
var regex = /\d*\.?\d?/g;
return regex.exec(element);
}
解决方案
试试这个Regex:
^ \d * \。?\ d + $
I am using a input of type number in which it allows multiple decimal points so i have tried using the regex not to allow more than one decimal point but even after using the regex i am facing the same issue can anyone tell me how to allow only one decimal point in input of type number in ionic1
Html:
<input stopccp focus-me class="inputContainer trade_input" type="number" name="" ng-model="vm.total_amount[$index]" ng-change="vm.onTotalCost()" limit-char limit="5" ng-keyup="vm.decimalcheck(vm.total_amount[$index])" >
Regex in function:
function decimalcheck (element) {
$log.log('decimalcheck got called', element);
var regex = /\d*\.?\d?/g;
return regex.exec(element);
}
解决方案
Try this Regex:
^\d*\.?\d+$
Explanation:
^
- Start of String\d*
- 0+ digits\.?
- 0 or 1 decimal point\d+
- 1+ digits(thus making it mandatory to have atleast one digit after the decimal point, if it is present)$
- End of String
OUTPUT:
这篇关于如何在离子1中仅允许一个小数点输入类型编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文