title: Enter only decimal value upto two decimal place in angular js
body: <p>How to enter decimal value upto two decimal place in textbox.please let me know how to modify this below directive.</p>
  
  <p>I have used below code</p>
  
  <pre><code>app.directive('nksOnlyNumber', function () {
      return {
          restrict: 'EA',
          require: 'ngModel',
          link: function (scope, element, attrs, ngModel) {
              scope.$watch(attrs.ngModel, function (newValue, oldValue) {
                  var spiltArray = String(newValue).split("");
                  if (spiltArray.length === 0) return;
                  if (spiltArray.length === 1
                       &amp;&amp; (spiltArray[0] == '-'
                       || spiltArray[0] === '.')) return;
                  if (spiltArray.length === 2
                       &amp;&amp; newValue === '-.') return;
  
                  /*Check it is number or not.*/
                  if (isNaN(newValue)) {
                      ngModel.$setViewValue(oldValue);
                      ngModel.$render();
                  }
              });
          }
      };
  });
  </code></pre>