25 Aralık 2018 Salı

Copy Paste Trim and Only Numeric

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);
}
}
}

Hiç yorum yok:

Yorum Gönder

.net 6 mapget kullanımı

 app.UseEndpoints(endpoints => {     endpoints.MapGet("/", async context =>     {         var response = JsonConvert.Seriali...