jQuery Plugin for Input Restriction And Validation - numeric.js

File Size: 8.36 KB
Views Total: 237
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Plugin for Input Restriction And Validation - numeric.js

numeric is a lightweight and fast jQuery plugin that enhances input validation by allowing only valid numbers to be entered into your input boxes. 

When users paste the content into the input boxes via Ctrl+V, the plugin automatically fixes the values to match your desired format.

Great for e-commerce websites and online stores to simplify data entry and validation, minimizing the risk of human error and ensuring data accuracy.

How to use it:

1. Download the plugin and put the jquery.numeric.js script after jQuery (slim build is recommended).

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/jquery.numeric.js"></script>

2. Attach the numeric function to any input fields you wish to restrict to numeric values.

<input class="numeric" type="text" />
$(function(){ 
  $(".numeric").numeric();
});

3. Determine whether to allow negative values. Default: true.

$(function(){ 
  $(".numeric").numeric({
    negative: false
  });
});

4. Restrict the input field to only allow x decimal places. Default: -1.

$(function(){ 
  $(".numeric").numeric({
    decimalPlaces : 2
  });
});

5. The JS shows how to change decimal point to comma. Default: -1.

$(function(){ 
  $(".numeric").numeric({
    decimal: ","
  });
});

6. Execute a function if the number is not valid (fires onblur).

$(function(){ 
  $(".numeric").numeric({
    // options here
  }, function(){
    // do something
  });
});

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