Input number accept point in firefox

Asked

Viewed 730 times

0

can help me?

I have this input number that must accept decimal values. People fill the decimal with a dot (.) and not a comma (,)

In all browsers works very well, EXCEPT in firefox which is our default browser. (Firefox is only allowing (,) and not (.))

inserir a descrição da imagem aqui

I searched several sites (including here in stackoverflow) and several methods, the only way it worked was to leave the input as text and apply a mask with js converting the (.) to (,) thus avoiding the doubt or the user’s Noob error.

Can I allow firefox to accept (.) input number? Does anyone know? Thank you!

2 answers

1

Note: Any number is an acceptable value, provided it is a valid floating point number (i.e., not Nan or Infinity).

"1.0" is different "1.0" has to see how your browser treats floating point;

Decimal separator have countries representing with ",", ex: R$; and countries representing with "." ex: $;

to accept "1.0" only it depends on the location of your browser it will turn to "1.0".

<input type="number" placeholder="1.0" step="0.01" min="0" max="10">

<html>
<body>
  <input type="number" placeholder="1.0" step="0.01" min="0" max="10">
</body>
</html>

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number

Curiosity: Even if you try to force it using toLocaleString() the input "number" follows the feature of the browser locale;

var number = 3.5;
document.getElementsByTagName("input")[0].value = number.toFixed(2).toLocaleString('en-US');
console.log(number.toLocaleString());
<html>
<body>
   <input type="number">
</body>
</html>

  • Thanks friend, From what I understand, so there is not much to do. It is a question of which browser I am using. If I want to force the use of (.) I have to configure a text field with a mask and then give due precautions to this field to only receive integer values.

  • @Shbr yes that’s it there!

  • Hello guys, all right!! I got a much simpler solution using <html lang="en">, so the browser interprets the site with the language I want, so (.) starts to be accepted!!! Big Hugs!!!

0


all right!! I got a much simpler solution using:

< html lang="en" >

This way the browser interprets the site with the language I want, so the point (.) starts to be accepted!!! Big Hugs!!!

  • Yes, it’s a good way out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.