diff --git a/src/app/components/keyfilter/keyfilter.ts b/src/app/components/keyfilter/keyfilter.ts index 05ef4efeb16..89206a8f026 100755 --- a/src/app/components/keyfilter/keyfilter.ts +++ b/src/app/components/keyfilter/keyfilter.ts @@ -113,7 +113,11 @@ export class KeyFilter implements Validator { lastValue: any; - constructor(@Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, public el: ElementRef) { + constructor( + @Inject(DOCUMENT) private document: Document, + @Inject(PLATFORM_ID) private platformId: any, + public el: ElementRef + ) { if (isPlatformBrowser(this.platformId)) { this.isAndroid = DomHandler.isAndroid(); } else { @@ -227,8 +231,9 @@ export class KeyFilter implements Validator { } let valueCheck = this.el.nativeElement.value || ''; - - let val = valueCheck + cc; + const selectionStart = (e.currentTarget).selectionStart || 0; + const selectionEnd = (e.currentTarget).selectionEnd || 0; + let val = valueCheck.substring(0, selectionStart) + cc + valueCheck.substring(selectionEnd); ok = (this.regex).test(val);