I have Input type number, and when I write 123-
I get an empty value from event.target.value
, but I want get value as I write in the input and replace the value with regex /(^([^-\d]*)|[^\d]*)/g
for empty value. It is possible to do it? How to get an exactly the same text from input?
It must be a type number because sometimes I need to use min
and max
attributes.
I want replace text via regex like this (value.replace(regex, ''
):
-123.123
into-123123
---123-456
into-123456
123-45
into12345
12e23,.-
into1223
const myFun = (e) =>
setTimeout(()=>{
console.log(e.target.value)}
)
<input onkeydown="myFun(event)" type="number"/>
originally i use angular 8 and host listener
@HostListener('input', ['$event']) // or/and keydown
onInputChange(event: Event): void {...}