angular numbers only directive

import { Directive, ElementRef, HostListener, Input } from '@angular/core';
import { NgControl } from '@angular/forms';

@Directive({
  selector: 'input[type=number], input[numbersOnly]'
})
export class NumbersOnlyInputDirective {

  constructor(private elRef: ElementRef) { }

  @HostListener('input', ['$event']) onInputChange(event) {
    const initalValue = this.elRef.nativeElement.value;
    this.elRef.nativeElement.value = initalValue.replace(/[^0-9]*/g, '');
    if ( initalValue !== this.elRef.nativeElement.value) {
      event.stopPropagation();
    }
  }

}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
onlynumber directive angular input number angular 8 angular directive only numbers angular directiive only numbers angular directive for numbers only html input field take number only angular angular input type text only number directive input angular numeric angular only accept integer no decimal mat input whole number only angular 5 input allow only numbers angular only number input regular expression to input integer only in html number field angular don't allow e in number input using regular expression in angular angular input only integers angular 2 allow only numbers and one dot input angular 2 allow only numbers and one dot site angular input with only input numbers angular input accept only numbers numbers only directive in angular ONLY NUMBER INPUT TEXT angular 10 numbers in angular directives numeric key angular validation angular numeric input how to accept only integer value and float value in angular input box parrten input text only numbers angular numeric fields for mobile digit only angular 4 allow only number input angular input field only numbers angular seven only allow numbers in input regex angular angular seven only allow numbers in input regex angular directive numbers only input accept only numbers angular input angular number only only numeric field in angular allow only numbers in input ts angularts only allow numbers in input allow number only angular number only directive angular numbers only validation angular 4 only numbers not allow angular 8 angular don't allow letters in input only english chrachter and number directive angular angular 8 input text only angular input text only angular input text onl angular input type number only angular digit only input app-text-input put only number angualr allow only numbers in textbox angular 10 make a field in angular numeric only angular 8 regex only number angular allow only numbers input angular 8 input text only number angular input text only number allow numbers only in textbox angular dont allow to enter more than 6 digits in input angular reaqctive form allow only numbers in input type text in angular 8 text only directive number only directive input allow only numbers angular 6 app numbers only angular directive allow only numbers directive angular angular directive for number validation how to enter numbers onlty in textbox angular allow only numbers in input angular 10 only phone number inputangular input type=text only numbers angular 8 dont allow 1. in number angular only number directive angular only numbers angular input allow only at the beginning of a number angular input accept only numbers directive angular matinput allow only numbers how to show only numbers angular angular text allow only number to type on keydown accept only numbers angular 8 angular directive to accept number and 2 alphabets ensure text field is only number angular angular input number only force tel field to only allow numbers in angular angular numeric field only numbers only angular only allow number and letter angular input mat input allow only letters angular 8 allow only numbers in angular angular directive accepts integer number directive angular 6 angular form input number only angular 9 input only numbers angular OnlyNumber what is angular OnlyNumber string number only input html angular mat input number 2 digit pattern html angular 7 input number only angular force numberic angular form accept only number directive angular pipe to accept number only in the range angular only allow numbers in input custom directive to only allow regex pattern in input field angular get only numeric in angular 6 in input get only numeric in angular 6 angular 4 directive to allow only numbers angular directive to allow only 4 numbers angular directive to allow only numbers angular directive to accept only numbers input field to accept only numbers angular 6 how to allow only pattern in input angular keypress validation directive in angular 6 angular 6 only allow numbers in input reactive forms angular 6 only allow numbers in input angular 6 input number only number only directive angular 4 how to check if only number is entered in the txt box angular accept only numeric values text field angular only allow digit in angular 7 directive number angular numbers only directive angular 6 angular numbers only directive
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source