Regular expression determines that the input is a number

clipboard.png

what is the role of value.replace (/ / g, ""). Length = = 0 ")?
can I delete it? (I deleted it and didn"t find anything wrong.)

Mar.10,2021

The main purpose of this sentence is to deal with strings that are full of spaces.
in fact, you can choose to determine whether the format is correct, so you don't have to determine whether the input is empty.
and that is, your regularity had better be changed to this

.
/^(?:[1-9]\d*|0)(?:\.\d+)?$/

the reason is that you can enter 00000000

for your rule.
Menu