Issue
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);
}
Solution
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
Answered By - Gurmanjot Singh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.