Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function inputNumber() {
- return {
- require: 'ngModel',
- link: function(scope, element, attrs, ctrl) {
- ctrl.$parsers.unshift(function(viewValue) {
- if (FLOAT_REGEXP.test(viewValue)) {
- ctrl.$setValidity('float', true);
- if (typeof viewValue === 'number') {
- return viewValue;
- } else {
- console.log(parseFloat(viewValue.replace(',', '.')));
- console.log(parseFloat(viewValue.replace(',', '.')) > 100000);
- return parseFloat(viewValue.replace(',', '.'));
- }
- } else {
- ctrl.$setValidity('float', false);
- return undefined;
- }
- });
- }
- };
- }
- Console output:
- false
- 10
- false
- 10.3
- false
- 10.32
- false
- 10321
- false
- 10.3211
- false
- 10.32111
- false
- 10.321111
- false
- 10.32111
- false
- 10.3211
- false
- 10321
- false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement