Is there any way to define an <input>
that shows a keyboard input that only allows numbers and the decimal point (or comma for international users)?
<input type='tel'>
shows phone crap I don't need, and no decimal point<input type='number' pattern='[0-9]*'>
shows all numbers, but no decimal point
What can I do to get the input I need?
Numbers that contain a decimal point are stored in a data type called REAL. Variables that use the real data type can accept both positive and negative numbers with a decimal place.
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.
By default, HTML 5 input field has attribute type=”number” that is used to get input in numeric format. Now forcing input field type=”text” to accept numeric values only by using Javascript or jQuery. You can also set type=”tel” attribute in the input field that will popup numeric keyboard on mobile devices.
NUMERIC Data Types. There are two different data types that allow us to store precise numerical data in SQL: NUMERIC and DECIMAL. Both of these types store decimal numbers and use exact arithmetic – as opposed to floating point numbers (REAL, FLOAT, etc.), which store binary numbers and use inexact arithmetic.
You can try this attribute to your type="number" field:
pattern="\d+(\.\d*)?"
this will allow only digits with/without a decimal point and the floating numbers on the right.
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