Force input fields to accept numeric value only.
- Include jQuery(local or CDN)
<script src="jquery-3.5.1.min.js"></script>
- Include plugin
<script src="numericInput.js"></script>
There are 2 ways to init an numeric input:
- Using jQuery selector
<input type="text" name="phone" />
<script src="jquery-3.5.1.min.js"></script>
<script src="numericInput.js"></script>
<script>
// Call on specified input
$(`input[name="phone"]`).numericInput();
</script>
- Using HTML
numericinput
andmaxdigits
attribute.
<input type="text" name="phone" numericinput maxdigits="3" />
<script src="jquery-3.5.1.min.js"></script>
<script src="numericInput.js"></script>
options
(default: {maxDigits: null}
)
Type: plainObject
options
accepts following properties:
maxDigits
: Maximum amount of digits.
Init numericInput on a specified jQuery selector.
1.0.0
Init release
1.0.1
Now run on dynamically added input.
1.0.2
Fix bug with dynamically added input.