blob: d00c52502c1609960905135bf243a60e657b3c18 [file] [log] [blame]
import {Directive, ElementRef, HostBinding, HostListener} from '@angular/core';
@Directive({
selector: '[patternInput]'
})
export class InputPreventionPatternDirective{
@HostListener('keypress', ['$event']) onKeypress(event: KeyboardEvent) {
const pattern = new RegExp(this.inputElement.nativeElement.pattern);
if(pattern){
if(!pattern.test(event['key'])){
event.preventDefault();
}
}
return event;
}
inputElement : ElementRef;
constructor(el: ElementRef) {
this.inputElement = el;
}
}