Skip to main content

Posts

Showing posts with the label Angular Allow Decimal Numbers with a Single Decimal

Angular Directive to Allow Decimal Numbers with a Single Dot (.)

In this example, we are determining if your input text-box  already has a decimal point , if you want to prevent enter another decimals character in the same text-box . After entered another decimal dot (.), the ASCII value will matches another entered decimal point in your text-box and remove if multiple entry . Let's see the example - app.directive( 'allowOnlyDecimalNumbers' , function () {     return {         restrict: 'A' ,         link: function (scope, elm, attrs, ctrl) {             elm.on( 'keydown' , function (event) {                 var $input = $( this );                  var value = $input.val();          ...