import { OnInit, Directive, HostListener, EventEmitter, Output } from "@angular/core";
@Directive({
selector: "[copyPasteTrimAndOnlyNumeric]",
providers: []
})
export class CopyPasteTrimAndOnlyNumericDirective {
@Output() ngModelChange: EventEmitter<any> = new EventEmitter();
value: any;
constructor() { }
ngOnInit(): void { }
@HostListener('paste', ['$event']) onPaste(e: ClipboardEvent) {
debugger
e.preventDefault();
let pastedText = e.clipboardData.getData('text');
if (pastedText) {
pastedText = pastedText.replace(/[^0-9]+/g, '')
if (pastedText && pastedText.length > 11)
pastedText = pastedText.substring(0, 11);
this.ngModelChange.emit(pastedText);
}
}
}