HTML input allow only numeric values | JavaScript
Following code allows exactly numbers and one decimal, but no more.
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" />

Numbers and One decimal, but no more.
<!DOCTYPE html>
<html>
<body>
<h2>Numbers and One decimal, but no more.</h2>
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" />
</body>
</html>
Allow only numeric values

By default, HTML 5 input field has attribute type="number" that is used to get input in numeric format. But you can force input field type="text" to accept numeric values only by using Javascript or jQuery. There are so many ways you can force the input field to take input only numbers.
Related Topics
- JavaScript Popup Boxes
- Opening a new window in JavaScript
- How to Create Drop-Down Lists in JavaScript
- How do I include a JavaScript file in another JavaScript file?
- Print the content of a Div using JavaScript/jQuery
- How to get the current URL using JavaScript ?
- How to Detect a Mobile Device with JavaScript/jQuery
- How to validate an email address in JavaScript
- JavaScript Array Iteration
- How to Remove a Specific Item from an Array in JavaScript
- What is JavaScript closures?
- How To Remove a Property from a JavaScript Object
- How to get selected value from Dropdown list in JavaScript
- How do I get the current date in JavaScript?
- How to Open URL in New Tab | JavaScript
- How to delay/wait/Sleep in code execution | JavaScript
- How to round to at most 2 decimal places | JavaScript
- How to convert string to boolean | JavaScript
- How to check undefined in JavaScript?
- How To Copy to Clipboard | JavaScript
- How to encode a URL using JavaScript?
- How to create multiline string in JavaScript
- How to Check for an Empty String in JavaScript?