/ngx-digit-only

An Angular directive to only allow [0-9] in the input box when typing, pasting or drag/dropping.

Primary LanguageTypeScriptMIT LicenseMIT

Angular DigitOnly Directive

An Angular directive only allows [0-9] in the input box when typing, pasting or drag/dropping. This directive handles both Windows keyboard and Mac keyboard.

Build Status npm

Installation

npm i -S @uiowa/digit-only

Usage

// in your Angular module
import { DigitOnlyModule } from '@uiowa/digit-only';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    BrowserModule,
    DigitOnlyModule
  ],
  ...
})
export class YourModule { }
// in your component.html
<input type="text" digitOnly>

// pull out the numeric keypad in mobile devices and tablets
<input type="text" name="zipcode" id="zipcode"
    placeholder="00000" maxlength="5"
    inputmode="numeric" pattern="[0-9]*" digitOnly>