To ensure the correct input unless what was pressed I have made an another approch:
first check step a directive and second step a Validate.service.ts:
The code snipped for the directive [InputStringRestrictive.directive.ts} is:
import {Directive, HostListener} from '@angular/core'; @Directive({ selector: '[jgInputStringRestriction]', standalone: true }) export class jgInputStringRestrictionDirective { constructor() { } @HostListener('keydown', ['$event']) onKeyDown(event: KeyboardEvent) { if (event.key === '0') { } else if (event.key === '1') { } else if (event.key === '2') { ... } else if (event.key === '9') { } else if (event.key === ',') { } else if (event.key === '.') { } else if (event.key === '_') { } else if (event.key === '-') { } else if (event.key === '+') { // } else if (event.key === '*') { // } else if (event.key === '/') { // } else if (event.key === '^') { } else if (event.key === 'Backspace') { } else if (event.key === 'Insert') { } else if (event.key === 'ArrowLeft') { } else if (event.key === 'ArrowRight') { } else if (event.key === 'Delete') { } else if (event.key === ' ') { // delete option, if only numbers are allowed } else if (event.key === 'a') { } else if (event.key === 'b') { ... } else if (event.key === 'ü') { } else if (event.key === 'ö') { } else if (event.key === 'A') { } else if (event.key === 'B') { ... } else if (event.key === 'Y') { } else if (event.key === 'Z') { } else { event.preventDefault(); } } }
and second snipset for validation (As in German will , instead . )
validate(val: number | string): number | string { val === typeof 'number' ? (this.x = parseFloat(val.replace(/,/, '.'))) : null; return val; }
I understand, that is a totally other way to do and will not answer your redux problem, but whitespace is no problem anymore.
The example is given on stackblitz : https://stackblitz.com/edit/stackblitz-starters-rywp1el8?file=src%2Fmain.ts,src%2FInputRestriction.directive.ts
ifstatement withevent.code !== "Space"will make theifreturns false when typing space.