android ios 只能輸入數字 不能輸入小數點的 函數 cordova

andriod  

1 function numericsonly(ob) {
2     var invalidChars = /[^0-9]/gi
3         if (invalidChars.test(ob.value)) {
4             ob.value = ob.value.replace(invalidChars, "");
5         }
6 }

調用的時候 

numericsonly(this)

iOS 

 1 function IsNum(e) {
 2     //alert("xx");
 3     var k = window.event ? e.keyCode : e.which;
 4     if (((k >= 48) && (k <= 57)) || k == 8 || k == 0) {}
 5     else {
 6         if (window.event) {
 7             window.event.returnValue = false;
 8         } else {
 9             e.preventDefault(); //for firefox
10         }
11     }
12 
13 }
//調用的時候 IsNum(event)
原文地址:https://www.cnblogs.com/xieyier/p/4015921.html