jQuery Plugin To Restrict Input To Numeric Values - Mask As Number

File Size: 24.2 KB
Views Total: 11000
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
jQuery Plugin To Restrict Input To Numeric Values - Mask As Number

Mask As Number is a lightweight and sometimes useful jQuery plugin which restricts the input fields to a specific number of numeric values and prevents invalid keystrokes. With support for max/min lengths or values. You can use this plugin to allow only numbers in your special inputs like currency and unit fields.

How to use it:

1. Place jQuery library and the jQuery Mask As Number plugin's JS file right before the closing body tag.

<script src="//code.jquery.com/jquery.min.js"></script>
<script src="jquery-mask-as-number.js"></script>

2. Active the plugin on the input fields.


3. Specify the max length using the native maxlength attribute:

<input class="maskedTextField" maxlength="8">

4. Specify the max / min values using the native data-mask-as-number-* attributes like this:

<input class="maskedTextField"

<input class="maskedTextField"

5. You can also set the max / min values in the JavaScript during init.

  min: 2, 
  max: 3



  • Now the maskAsNumber method returns itself for cascading. Startup on chrome fixed when the default value is invalid


  • Now the method to extract the real value from number input field doesn't close the android keyboard (when changing input type)


  • Fixed cases when missing "data" on element
  • Now supports decimals!


  • Fixed min/max defined as options

v1.1 (2016-12-10)

  • Added paste event support, removed useless stored data, improved max value handling

This awesome jQuery plugin is developed by andrehtissot. For more Advanced Usages, please check the demo page or visit the official website.