Angular.js – using angular.isNumber() function
A simple Angular.js example of checking if a variable is a number with AngularJS API.
<!DOCTYPE html>
<html ng-app="testApp">
<head>
<style>
</style>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="Tizen Angular.js example"/>
<title>Tizen Angular.js example</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/angular.min.js"></script>
<script>
var app = angular.module('testApp', []);
app.controller('AppController', function($scope) {
$scope.obj1 = 123214234235454;
$scope.obj2 = "5435345345346546";
$scope.check = function() {
$scope.check1 = angular.isNumber($scope.obj1);
$scope.check2 = angular.isNumber($scope.obj2);
}
});
</script>
</head>
<body>
<div ng-controller="AppController">
<br>
$scope.obj1 = 123214234235454;<br>
$scope.obj2 = "5435345345346546";
<br><br>
<button ng-mousedown="check()">
Click this button to check if values are numbers
</button>
<br><br>
Is the <b>$scope.obj1</b> is a number: <b> {{ check1 }} </b>
<br><br>
Is the <b>$scope.obj2</b> is a number: <b> {{ check2 }} </b>
</div>
</body>
</html>