I currently have an input box component and I'd like to add a script to prevent all input except for numbers.
function onChangeHandler(e: React.ChangeEvent) {
this.value.replace(/(?![0-9])./gmi,'');
}
export function Input(props: InputProps) {
const {
className,
...restProps
} = props;
return (
<input
{...restProps}
className={cx([inputStyles])}
type={inputType}
onChange={e => onChangeHandler(e)}
/>
);
}
Currently this setup doesn't work because I get the following error from onChangeHandler: 'this' implicitly has type 'any' because it does not have a type annotation.
How can I make this work?
Note: I don't want to use type=number