tengo una entrada y solo acepta números decimales, usé una directiva numérica personalizada para validar y funciona con el teclado ENG, pero cuando cambio el teclado de la ventana a chino o japonés, no funciona, la directiva numérica de código a continuación, por favor ayúdenme, Gracias
import { Directive, ElementRef, HostListener, Input } from "@angular/core"; @Directive({ selector: "[numeric]", }) export class NumericDirective { @Input("decimals") decimals: number = 0; private check(value: string, decimals: number) { if (decimals <= 0) { return String(value).match(new RegExp(/^\d+$/)); } else { var regExpString = "^\\s*((\\d+(\\.\\d{0," + decimals + "})?)|((\\d*(\\.\\d{1," + decimals + "}))))\\s*$"; return String(value).match(new RegExp(regExpString)); } } private specialKeys = [ "Backspace", "Tab", "End", "Home", "ArrowLeft", "ArrowRight", "Delete", ]; constructor(private el: ElementRef) {} @HostListener("keydown", ["$event"]) onKeyDown(event: KeyboardEvent) { if (this.specialKeys.indexOf(event.key) !== -1) { return; } // Do not use event.keycode this is deprecated. // See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode const current: string = this.el.nativeElement.value; const position = this.el.nativeElement.selectionStart; const next: string = [ current.slice(0, position), event.key === "Decimal" ? "." : event.key, current.slice(position), ].join(""); if (next && !this.check(next, this.decimals)) { event.preventDefault(); } } }