Top Related Projects
Format input text content when you are typing...
Input mask for React, Angular, Ember, Vue, & plain JavaScript
A jQuery Plugin to make masks on form fields and HTML elements.
jQuery Masked Input Plugin
Quick Overview
Inputmask is a JavaScript library that helps create and manage input masks for form fields. It allows developers to define specific formats for user input, ensuring data consistency and reducing errors in data entry. The library supports various input types and is highly customizable.
Pros
- Easy to implement and integrate with existing forms
- Supports a wide range of input formats (dates, phone numbers, currency, etc.)
- Highly customizable with many options and extensions
- Works with both vanilla JavaScript and popular frameworks like jQuery
Cons
- Can be overwhelming for beginners due to the large number of options
- Some users report occasional issues with mobile device compatibility
- Documentation could be more comprehensive and better organized
- Performance may be impacted when using multiple masks on a single page
Code Examples
- Basic phone number mask:
Inputmask("(999) 999-9999").mask(document.querySelector("#phone"));
- Date mask with custom placeholder:
Inputmask("99/99/9999", { placeholder: "dd/mm/yyyy" }).mask(document.querySelector("#date"));
- Currency mask with prefix and suffix:
Inputmask("currency", {
prefix: "$ ",
suffix: " USD",
digits: 2
}).mask(document.querySelector("#price"));
- Custom mask for a product code:
Inputmask("aa-9{1,4}", {
definitions: {
"a": { validator: "[A-Za-z]", cardinality: 1 }
}
}).mask(document.querySelector("#product-code"));
Getting Started
To use Inputmask in your project, follow these steps:
- Include the Inputmask library in your HTML file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/inputmask/5.0.7/jquery.inputmask.min.js"></script>
- Apply a mask to an input field:
document.addEventListener("DOMContentLoaded", function() {
var element = document.querySelector("#masked-input");
var im = new Inputmask("99-9999999");
im.mask(element);
});
- For more advanced usage, refer to the official documentation and explore the various options and extensions available.
Competitor Comparisons
Format input text content when you are typing...
Pros of Cleave.js
- Lightweight and focused on input formatting
- Easy to set up and use with minimal configuration
- Supports both vanilla JavaScript and popular frameworks like React and Angular
Cons of Cleave.js
- Limited customization options compared to Inputmask
- Fewer input types and formatting options available
- Less active development and community support
Code Comparison
Cleave.js:
new Cleave('.input-phone', {
phone: true,
phoneRegionCode: 'US'
});
Inputmask:
Inputmask({
mask: '(999) 999-9999',
placeholder: ' '
}).mask('.input-phone');
Both libraries aim to simplify input formatting, but Inputmask offers more advanced features and customization options. Cleave.js is easier to set up and use for basic formatting needs, while Inputmask provides greater flexibility for complex input scenarios.
Cleave.js is ideal for projects requiring simple, lightweight input formatting, whereas Inputmask is better suited for applications with diverse and complex input requirements. The choice between the two depends on the specific needs of your project and the level of customization required.
Input mask for React, Angular, Ember, Vue, & plain JavaScript
Pros of text-mask
- Lightweight and focused solely on input masking
- Easy to integrate with various frameworks (React, Angular, Vue, etc.)
- Supports both vanilla JavaScript and framework-specific implementations
Cons of text-mask
- Less feature-rich compared to Inputmask
- Smaller community and fewer updates
- Limited options for complex masking scenarios
Code Comparison
text-mask:
import { createTextMaskInputElement } from 'text-mask-core'
const phoneMask = ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]
const maskedInputElement = createTextMaskInputElement({
inputElement: document.querySelector('#phone-input'),
mask: phoneMask
})
Inputmask:
import Inputmask from "inputmask";
Inputmask("(999) 999-9999").mask(document.querySelector("#phone-input"));
Both libraries offer input masking functionality, but Inputmask provides a more concise syntax for common use cases. text-mask offers more granular control over mask definition, while Inputmask has a wider range of pre-defined masks and options. Inputmask is generally more feature-rich and flexible, but text-mask may be preferred for simpler use cases or when a lightweight solution is needed.
A jQuery Plugin to make masks on form fields and HTML elements.
Pros of jQuery-Mask-Plugin
- Lightweight and simple to use, with a focus on jQuery integration
- Extensive documentation and examples for common use cases
- Supports custom definitions for creating unique mask patterns
Cons of jQuery-Mask-Plugin
- Dependent on jQuery, which may not be ideal for modern web applications
- Less flexible for complex masking scenarios compared to Inputmask
- Limited built-in mask types and fewer configuration options
Code Comparison
jQuery-Mask-Plugin:
$('#date').mask('00/00/0000');
$('#phone').mask('(000) 000-0000');
$('#custom').mask('AA-00-SSSS');
Inputmask:
Inputmask("datetime", {
inputFormat: "dd/mm/yyyy"
}).mask("#date");
Inputmask("(999) 999-9999").mask("#phone");
Inputmask("aa-99-****", {
definitions: {'*': {validator: "[A-Za-z0-9]"}}
}).mask("#custom");
The code comparison shows that jQuery-Mask-Plugin offers a simpler syntax for basic masking, while Inputmask provides more detailed configuration options for complex scenarios. Inputmask's approach allows for greater flexibility in defining masks and handling various input types, but may require more setup for simple use cases.
jQuery Masked Input Plugin
Pros of jquery.maskedinput
- Lightweight and simple to use
- Well-established with a long history of development
- Good compatibility with older jQuery versions
Cons of jquery.maskedinput
- Requires jQuery as a dependency
- Less actively maintained compared to Inputmask
- Limited features and customization options
Code Comparison
jquery.maskedinput:
$("#phone").mask("(999) 999-9999");
$("#date").mask("99/99/9999");
Inputmask:
Inputmask("(999) 999-9999").mask("#phone");
Inputmask("99/99/9999").mask("#date");
Both libraries offer similar syntax for basic masking, but Inputmask provides more advanced features and options for complex scenarios. Inputmask supports various input types, including numeric, currency, and date inputs, with extensive customization possibilities.
While jquery.maskedinput is simpler and may be suitable for basic masking needs, Inputmask offers a more comprehensive solution with better performance and flexibility. Inputmask is also actively maintained and doesn't require jQuery, making it a more future-proof choice for modern web development projects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Inputmask
Copyright (c) 2010 - 2023 Robin Herbots Licensed under the MIT license (https://opensource.org/licenses/MIT)
The Inputmask has a very permissive license and this will stay that way. But when you use the Inputmask in a commercial setting, be so honest to make a small donation. This will be appreciated very much.
Inputmask is a javascript library that creates an input mask. Inputmask can run against vanilla javascript, jQuery, and jqlite.
An inputmask helps the user with the input by ensuring a predefined format. This can be useful for dates, numerics, phone numbers, ...
Thanks to Jetbrains for providing a free license for their excellent Webstorm IDE.
Thanks to Browserstack for providing a free license, so we can automate testing in different browsers and devices.
Documentation and demo page
Top Related Projects
Format input text content when you are typing...
Input mask for React, Angular, Ember, Vue, & plain JavaScript
A jQuery Plugin to make masks on form fields and HTML elements.
jQuery Masked Input Plugin
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot