user3045654
user3045654

Reputation: 1734

Only integer numbers allow print in input

I am use AngularJS and Kendo UI. I want to print only integer numbers in my input component. I have tried using regular expressions but it did not help me.

This my config for input:

input(
    ng-pattern='vm.regexp'
    min='1'
    ng-model='vm.maxContentCounter'
)
vm.regexp = /^(0|[1-9]\d*)$/;

This input allows print comma and dots, and I can print value less then 1. How I can allow print only integer values?

Upvotes: 0

Views: 65

Answers (1)

phani indra
phani indra

Reputation: 243

<html ng-app="myApp">
<head>
	<title></title>
</head>
<body ng-controller="myCtrl">
<input type="text" valid-decimal-number ng-model="Amount"  ng-blur="ConvertToDecimal()">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller('myCtrl', ['$scope', function ($scope) {
$scope.ConvertToDecimal = function (val) {
	if(isNaN($scope.Amount)){
		alert("given input is not a number");
		return;
	}
        var num = Number($scope.Amount);
        var dupNum=Math.floor(num);
        if(num !=dupNum){
        alert("given input is not a number");
		return;
        }
        $scope.Amount=num;
    }
}]);
</script>
</body>
</html>

Upvotes: 1

Related Questions