inputmask

repository·5.x·Indexed 27 days ago

https://github.com/robinherbots/inputmask

A JavaScript library for creating input masks to enforce predefined formats on user input fields, such as dates, phone numbers, and numeric values. It is compatible with vanilla JavaScript, jQuery, and jqlite. Features include a datetime extension, Colormask for colored mask characters, and support for custom definitions, aliases, and declarative masking via data-inputmask attributes.

Tokens
11K
Snippets
28
Records
78
Agent score
91%

What's inside inputmask

  1. Overview of Inputmask

    5.x
    Inputmask is a JavaScript library designed to create input masks for various input types such as dates, numerics, and phone numbers. It ensures users follow a predefined format during data entry. The library is compatible with vanilla JavaScript, jQuery, and jqlite.
  2. Install Inputmask via npm or script tags

    5.x

    You can integrate Inputmask into your project using several methods depending on your environment.

    Webpack / npm

    Install the package using npm:

    npm install inputmask --save

    To use it in your modules:

    // CommonJS
    var Inputmask = require('inputmask');
    
    // ES6
    import Inputmask from "inputmask";

    Classic Web (Script Tags)

    Include the files from the dist folder.

    With jQuery dependency:

    <script src="jquery.js"></script>
    <script src="jquery.inputmask.js"></script>

    Vanilla JS (no jQuery):

    <script src="inputmask.js"></script>

    Automatic Binding: To automatically bind masks to inputs with data-inputmask-... attributes, include the binding script:

    <script src="bindings/inputmask.binding.js"></script>
    npm install inputmask --save
  3. Set initial values for numeric inputs

    5.x

    When initializing a mask with a value, the interpretation depends on the inputType option:

    1. If inputType is text: The value must match the radixPoint symbol (e.g., if radixPoint is ,, the value must use ,).
    2. If inputType is number: The value must use . as the radix point.

    Note on jQuery: Using `$(

    /html
    <input name="npt" value="123456,789"/>
    
    //js
    Inputmask("decimal", {
        radixPoint: ',',
        inputtype: "text"
    }).mask("input");
    
    // Using jQuery (Note: jQuery converts numbers to strings, which may break radixPoint logic)
    $("input").val("123456,789");
    $("input").val(123456.789); 
    
    // Using Vanilla JS (Recommended for precision)
    document.getElementsByName("npt")[0].value = "123456,789";
    document.getElementsByName("npt")[0].value = 123456.789; // type number