angularjs: allow only integer in html input

allow only numbers and decimal in textbox angularjs
angular 7 input number only
angularjs input number only
angular 6 input number only
angularjs ng-pattern only numbers
allow only alphabets in textbox using angular 6
how to enter only numbers in textbox using angularjs
input type=number prevent e angular 4

<md-input-container flex>
  <label>{{'COMMON.AMOUNT' | translate }}</label>
  <input class="margin-top-2" id="depositpaidamount" enterastab name="disabledamount" type="number" ng-model="deposit.paidamount" ng-disabled="true" />

use onkeypress event in your input box

<input type="text" onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || event.charCode <= 31'>

How to allow only integer numbers in Angular?, <script src=" <div ng-app​> <div ng-controller="Main"> <form name="form"> <input  Content updated daily for angularjs development. Get reliable information in seconds. Search Teoma today!

You need to add a check in JavaScript Controller for this if entered value is a integer or not.

Below is working code:

var invalidChars = ["-","+","e","."];

depositpaidamount.addEventListener("keydown", function(e) {
  if (invalidChars.includes(e.key)) {
<md-input-container flex>
  <label>{{'COMMON.AMOUNT' | translate }}</label>
  <input class="margin-top-2" id="depositpaidamount" enterastab name="disabledamount" type="number" ng-model="deposit.paidamount" ng-disabled="true" />

input[number], In browsers that follow the HTML5 specification, input[number] does not work The step validation will not work correctly for very large numbers (e.g. Setting the attribute to a negative or non-numeric value, allows view values of any length. Text Input allow only Integer input in angularjs. I want to set the html input[number] <input type="number" /> to allow only integer input (not float). Basically, the html input[number] allow '.' to be entered for float input and I don't want that.

Use Directive

app.directive('restrictTo', function () {
return {
    restrict: 'A',
    link: function (scope, element, attrs) {
        var re = RegExp(attrs.restrictTo);
        var exclude = /Backspace|Enter|Tab|Delete|Del|ArrowUp|Up|ArrowDown|Down|ArrowLeft|Left|ArrowRight|Right/;

        element[0].addEventListener('keydown', function (event) {
            if (!exclude.test(event.key) && !re.test(event.key)) {

And In HTML we use following way:
<input type="text" restrict-to="[0-9]"/>

See the Plunker Example HERE.. Visit:

If useful to you please mark it as answer.

Digit Only Directive in Angular, Natural numbers are frequently used as Account Numbers, With the help of Angular directive, input box will only allow [0–9] Or you can ignore HTML5 form validation and use form validations in front-end frameworks. I am new to angularjs. I am wondering what is the way to allow only a valid number typed into a textbox. For example, user can type in "1.25", but cannot type in "1.a" or "1..". When user try to t

AngularJS Numbers Only Directive, <p>Input below will accept only numbers.</p>. 6. ​. 7. <p><input type="text" ng-​model="val" numbers-only class="form-control" /></p>. 8. 9. 10. </div>. It restricts input to only numbers and decimal point in a textbox while typing. It also trims the digits after the decimal point if the decimal point is removed from the textbox e.g. if you have put 123.45 and then remove the decimal point it will also remove the trailing digits after the decimal point and make it 123.

AngularJs attribute directive to accept only numbers in a text box , var app = angular.module('plunker', ['number']); app.controller('MainCtrl', function​($scope) { $ = ''; }); <!DOCTYPE html> <html ng-app="plunker">  This module is added to the HTML page using the ng-app directive. Then I created the directive with the name "allowOnlyNumbers". If you are creating any kind of directive using AngularJs then you must always check that the name is provided using "-" in your HTML page and these dashes "-" will be replaced by capital letters in the Angular code.

NG Numbers Only, <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>NG Numbers Only - Input number with digit issue fixed</title> <script  In browsers that follow the HTML5 specification, input [number] does not work as expected with ngModelOptions. allowInvalid. If a non-number is entered in the input, the browser will report the value as an empty string, which means the view / model values in ngModel and subsequently the scope value will also be an empty string.

  • This is not correct answer. User can enter dot which should not be.
  • i edited my answer jst removing 46 key code, try again
  • But this will not work if user do copy-paste. User can not enter non-integer from keyboard BUT can paste
  • use - ** onpaste="return false" **
  • onpaste="return false" is not good option. What if user want to paste a valid integer?
  • Is there any option to do only in html
  • @SrividhyaS you need to take care of for case of copy-paste as well. This code will prevent user to enter non-integer from keyboard as well as from copy-paste. Tester will raise a bug for this, so Keep in mind :)
  • @ShrividyaS - my example above will take care of copy-paste issue as well.