I'm building for mobile.
I have a form that includes an input type number. When the device language is set to Arabic whenever I set a value to this input it will show it in Arabic numbers.
If I do something like this:
document.getElementById('input-id').value = 444
In the UI, we can see the input will have a value of ٤٤٤, this is the equivalent to 444 in Arabic numerals.
I don't have this issue in Input type="text" because it shows an String of characters so it doesn't convert them.
I know that I could use an Input type text instead but I would like to keep the consistency with the rest of my application and use an Input type number
I have this issue in Chrome, Safari and Firefox.
Clarification: I don't want it to translate it to Arabic Numerals. How can I make this?
<input type="number"> <input> elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries. The browser may opt to provide stepper arrows to let the user increase and decrease the value using their mouse or by tapping with a fingertip.
You can also use a decimal value: for example, a step of 0.3 will allow values such as 0.3, 0.6, 0.9 etc, but not 1 or 2. Now you don't get a validation error.
It's normal you get a string. The purpose of the number type is that mobile browsers use this for showing the right keyboards and some browsers use this for validation purposes. For example the email type will show a keyboard with the @ and '. ' on the keyboard and number will show a numeric keyboard.
HTML input number type allows "e/E" because "e" stands for exponential which is a numeric symbol. Example 200000 can also be written as 2e5. I hope this helps thank you for the question. Save this answer.
The HTML specification's section on the Number input
type states:
Note: This specification does not define what user interface user agents are to use; user agent vendors are encouraged to consider what would best serve their users' needs. For example, a user agent in Persian or Arabic markets might support Persian and Arabic numeric input (converting it to the format required for submission as described above). Similarly, a user agent designed for Romans might display the value in Roman numerals rather than in decimal; or (more realistically) a user agent designed for the French market might display the value with apostrophes between thousands and commas before the decimals, and allow the user to enter a value in that manner, internally converting it to the submission format described above.
This implies that it's down to the browser to determine what would "best serve their users' needs". I imagine the only way to override this would be by setting the language of your page to a language which does represent ٤٤٤
as 444
(such as English). To do this, we simply:
<body lang="en">
However, again, this is entirely down to the browser to decide whether to adhere to this.
You can specify the language attribute only for the desired input, for example,
<input type="number" lang="en">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With