Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing an input that only allows numbers and the decimal point?

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?

like image 953
Stefan Kendall Avatar asked Feb 09 '12 02:02

Stefan Kendall


People also ask

What is the data type that can handle numbers with a decimal point?

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.

Can input type number accept decimal?

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.

How do you make an input only accept the number?

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.

Which data type will allow decimal numbers?

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.


1 Answers

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.

like image 131
Paris Char Avatar answered Sep 23 '22 18:09

Paris Char