1 import {Directive, ElementRef, HostBinding, HostListener} from '@angular/core';
4 selector: '[patternInput]'
6 export class InputPreventionPatternDirective{
7 @HostListener('keypress', ['$event']) onKeypress(event: KeyboardEvent) {
8 const pattern = new RegExp(this.inputElement.nativeElement.pattern);
10 if(!pattern.test(event['key'])){
11 event.preventDefault();
17 inputElement : ElementRef;
18 constructor(el: ElementRef) {
19 this.inputElement = el;