Masked Input Component for React

2.0.4 · maintenance · verified Sun Apr 19

react-input-mask provides a simple and effective masked input component for React applications, allowing developers to enforce specific input formats such as phone numbers, dates, or social security numbers. The current stable version is 2.0.4, which was released approximately six years ago. The project appears to be in maintenance mode, with no significant updates since then. Its primary differentiator is its focused scope and direct integration into React workflows, offering a straightforward API for controlling input masking behavior and supporting dynamic mask changes. It's widely adopted for basic input masking requirements in React.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic phone number input with a mask, using a functional component with React hooks.

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

function PhoneInput() {
  const [phone, setPhone] = useState('');

  const handleChange = (e) => {
    setPhone(e.target.value);
  };

  return (
    <div>
      <label htmlFor="phone-number">Phone Number:</label>
      <InputMask
        mask="+1 (999) 999-9999"
        value={phone}
        onChange={handleChange}
        maskChar="_"
        placeholder="+1 (___) ___-____"
        id="phone-number"
        className="form-input"
      >
        {(inputProps) => <input {...inputProps} type="tel" />}
      </InputMask>
      <p>Current Value: {phone}</p>
    </div>
  );
}

export default PhoneInput;

view raw JSON →