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

react-input-mask

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-input-mask

Masked input component for React

  • 2.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
607K
increased by4.54%
Maintainers
1
Weekly downloads
 
Created

What is react-input-mask?

The react-input-mask package is a versatile input masking library for React applications. It allows developers to create input fields with predefined formats, ensuring that users enter data in a consistent and expected manner. This is particularly useful for fields like phone numbers, dates, and credit card numbers.

What are react-input-mask's main functionalities?

Basic Input Masking

This feature allows you to create a basic input mask for phone numbers. The mask prop defines the format, and the input field will automatically enforce this format as the user types.

import React from 'react';
import InputMask from 'react-input-mask';

function PhoneInput() {
  return (
    <InputMask mask="(999) 999-9999" placeholder="Enter phone number" />
  );
}

export default PhoneInput;

Custom Masking Characters

This feature allows you to define custom masking characters. In this example, the mask includes both numbers and letters, and the maskChar prop specifies the character to use for unfilled positions.

import React from 'react';
import InputMask from 'react-input-mask';

function CustomMaskInput() {
  return (
    <InputMask mask="99-aaa-9999" maskChar="_" placeholder="Enter custom format" />
  );
}

export default CustomMaskInput;

Masking with Validation

This feature demonstrates how to use input masking with state management and validation. The input field is masked for a credit card number, and the value is managed using React's useState hook.

import React, { useState } from 'react';
import InputMask from 'react-input-mask';

function ValidatedInput() {
  const [value, setValue] = useState('');
  const handleChange = (e) => {
    setValue(e.target.value);
  };
  return (
    <InputMask mask="9999-9999-9999-9999" value={value} onChange={handleChange} placeholder="Enter credit card number" />
  );
}

export default ValidatedInput;

Other packages similar to react-input-mask

Keywords

FAQs

Package last updated on 01 Sep 2018

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