Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-imask

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-imask

React input mask

  • 5.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
259K
decreased by-21.56%
Maintainers
1
Weekly downloads
 
Created

What is react-imask?

The react-imask package is a versatile input masking library for React applications. It allows developers to create input fields with predefined formats, ensuring that user input adheres to specific patterns. This is particularly useful for forms that require inputs like phone numbers, dates, credit card numbers, and more.

What are react-imask's main functionalities?

Basic Input Masking

This feature allows you to create a basic input mask for phone numbers. The mask ensures that the input follows the pattern (000) 000-0000.

import React from 'react';
import IMask from 'react-imask';

function PhoneInput() {
  return (
    <IMask.Input
      mask="(000) 000-0000"
      placeholder="(123) 456-7890"
    />
  );
}

export default PhoneInput;

Dynamic Masking

This feature demonstrates dynamic masking, where the input mask changes based on the input value. For example, it changes the mask for American Express card numbers.

import React, { useState } from 'react';
import IMask from 'react-imask';

function DynamicMaskInput() {
  const [mask, setMask] = useState('0000 0000 0000 0000');

  return (
    <IMask.Input
      mask={mask}
      placeholder="Enter your card number"
      onAccept={(value, mask) => {
        if (value.startsWith('34') || value.startsWith('37')) {
          setMask('0000 000000 00000'); // American Express
        } else {
          setMask('0000 0000 0000 0000'); // Other cards
        }
      }}
    />
  );
}

export default DynamicMaskInput;

Custom Masking with Regular Expressions

This feature allows you to use regular expressions for custom input masking. In this example, the input only accepts lowercase letters.

import React from 'react';
import IMask from 'react-imask';

function RegexMaskInput() {
  return (
    <IMask.Input
      mask={/^[a-z]*$/}
      placeholder="Enter lowercase letters only"
    />
  );
}

export default RegexMaskInput;

Other packages similar to react-imask

Keywords

FAQs

Package last updated on 14 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc