I am trying to remove everything except numbers, colon (:) and a new line. After having entered values with colon say 12:30, when I press enter, I am not able to submit using custom directives. So as of now, I am able to allow numbers and colon but not the enter key.
My custom directive looks something like this :
export class NumberDirective {
constructor(private _el: ElementRef) { }
@HostListener('input', ['$event']) onInputChange(event) {
const initalValue = this._el.nativeElement.value;
this._el.nativeElement.value = initalValue.replace(/[^0-9:\n]*/g, '');
if ( initalValue !== this._el.nativeElement.value) {
event.stopPropagation();
}
}
Please let me know how this can be fixed and thanks in advance.