leading zeros are not deleted. I also saw a lot of...">

Remove leading zeros from input type = number

I noticed that if I use <input type="number" />leading zeros are not deleted. I also saw a lot of discussion on how to maintain leading zeros.

For example, “000023” and “23” are the same number, and I think it makes no sense by storing these zeros.

+4
source share
5 answers

just use a regex like this

textboxText= textboxText.replace(/^0+/, '')
+8
source

Incoming Html tags always return text, not numbers, even its contents can be forcibly applied to number format, dates, etc.

So you have to convert this input to the actual number format:

parseInt(myNum); // If you expect an integer.
parseFloat(myNum); // If you expect floating point number.
+3
source

.

    str1 = str.replace(/^0+/,'');
0

:

<!DOCTYPE html>
<html>
<body>

<input type="number" id="txtfield" /><button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var myNumber = document.getElementById("txtfield").value;
    document.write(parseInt(myNumber ,10));
}
</script>

</body>
</html>
0

HTML5 <input type="tel">

0

All Articles