Firefox: how to show number input value with decimal spaces - html

I am only having this issue on firefox, it works as expected on chrome.
If I have a number input with a value of "20.00" or 20.00 (as a string or number) it always shows 20 without the decimal spaces inside the input box.
I need the type="number" so avoid other inputs that aren't numbers because of internal calculations that are done after the input.
For example:
<label>Input with number value as string</label>
<input type="number" value="20.00" step="0.01">
<br>
Input with number value as number
<input type="number" value=20.00 step="0.01">
How can I have the value inside the input show with the 2 decimal values in firefox?

Related

HTML form input number field truncates number after first decimal if the second decimal is a zero, but not if the first decimal is a zero

My code looks like this:
<input id="tt" name="tt" type="number" value="106.00" min="0.00" step="0.01" class="form-control input-md" oninput="calc()">
Now in the calc javascript function I have tried the following:
_("tt").value=total.toFixed(2);
_("tt").value=parseFloat(total).toFixed(2);
and both times I have this weird behaviour in Firefox (and only in Firefox) that the number field can show "106.00", for instance, but instead of "106.10" it shows "106.1" , i.e., there it truncates the last zero. I want it to show "106.10" as is it a monetary value. I am a bit at a loss as to why this odd behaviour in Firefox. Does anyone have an idea how to solve this?

unable to iterate large numbers in input

I have simple input box of type number with step='0.01'. I'd like to increase the current input value by the pre-defined step value using the up and down buttons situated on the very right side.
Now everything seems to work just fine while the number is less than or equals 13 digits. If it's greater it won't neither decrease nor increase the number by the step value. It just freezes the value not letting the user change the value using the up/down buttons.
<input id="test" type="number" min="0.00" value="" placeholder="" step="0.01" />

How can I specify the exact number of digits that an user have to insert into an input field?

I am pretty new in HTML and I have the following problem. Into a page I have an input tag like this:
<input id="codiceFiscaleEnte" class="form-control" name="numeroProtocollo" type="number" th:value="*{codiceFiscaleEnte}" required="required"></input>
and I have to do some validation on it.
So I know that the required="required" attribute means that the user have to insert a value for this field and that the type="number" specify that this value have to represent a number.
Can I specify in some way that this number has to be composed by exactly 11 digits? How can I do it using HTML attributes?
Use pattern:
<input type="text" name="numeroProtocollo" required pattern="[0-9]{11}">
It allows only numbers with a minimum and maximum length of 11
Test it:
https://jsfiddle.net/oegjdszx/1/
Use the pattern like this
<input pattern="[0-9]{5}">
Where 5 is the number of digits that you want.
<input type="number" min="10000000000" max="99999999999" required>
min and max attributes specify the smallest and largest valid values. An 11 digit number is a number between 10^10 and (10^11 - 1), so set min and max to those values

Static Input Violating MaxLength property of an input box

I have created an input box using <input type="text" name="username"> for user to input username, then i have fixed the length to 5 for some calculation.
<input type="text" name="username" maxlength="5">. but when i given the input as static text then it will accept any number of characters.
Setting max length to 5 means that the input box will hold only 5, then why it holds more than 5 letters when given like this?
<input type="text" name="username" maxlength="5" value="12345678910">
According to w3schools,
Maxlength eflects the maxlength HTML attribute, containing the maximum length
of text (in Unicode code points) that the value can be changed to. The
constraint is evaluated only when the value is changed
The key here is that it is only evaluated when the value is changed. You can set the value to anything when you're creating the element. The effect will take place after you change it. Try changing the input from your example, and you'll see that it does cap it at 5 characters.

Forbid letters in number field in html5

I want to prevent the user from entering non-numeric characters in a textfield for telephone number in HTML5. I tried this, but it doesn't forbid non-numeric characters:
<input type="tel" name="usrtel"><br>
I tried using type=number as well, but that gives me a up and a down arrow to increase or decrease the value, which is not useful for telephone numbers. How can I accomplish this?
You can use pattern attribute with a regex \d*
<input type="tel" name="usrtel" pattern="\d*" />
Demo (After typing in the box, just click anywhere outside the box, if you type in anything except the integers, it will show a red box, else it will stay normal)
Demo 2 (With custom message and submit button)
As you commented, you can change your pattern value to ^[0-9]{3,45}$ where user will have to input minimal of 3 digits to maximum of 45 in length.
Demo
<input
type="tel"
name="usrtel"
pattern="^[0-9]{3,45}$"
title="You can only enter numbers, with a minimal of 3 characters
upto 45 characters are accepted."
required="required"
/>
In the above markup, am using a title which will throw a custom error to your user.