npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@altricade/react-mask-field

v1.2.1

Published

A modern, flexible and accessible input mask component for React

Downloads

37

Readme

React Mask Field

A lightweight, flexible input masking library for React applications built with TypeScript. This library provides customizable masked input components with type safety and modern React practices.

Storybook npm version TypeScript React

Features

  • 🚀 Modern React API - Based on hooks and functional components
  • 📦 Lightweight - No external dependencies
  • 🔒 Type-safe - Written in TypeScript with full type definitions
  • 🧰 Specialized Components - Components for common use cases like phone numbers, dates, and credit cards
  • 🎨 Customizable - Flexible formatting options
  • ⚛️ Compatible - Works with React 16.8+ including React 18 and React 19
  • 🛡️ Clean DOM - Properly filters out non-standard props from DOM elements
  • 📚 Interactive Documentation - Comprehensive Storybook documentation with live examples

Documentation

Explore our interactive component documentation with live examples:

View Storybook Documentation

The Storybook provides:

  • Interactive examples of all components
  • Configurable props with live preview
  • Code snippets for common use cases
  • Detailed API documentation

For information on building and deploying the Storybook, see STORYBOOK.md.

Installation

npm install @altricade/react-mask-field
# or
yarn add @altricade/react-mask-field
# or
pnpm add @altricade/react-mask-field

Basic Usage

import React from 'react';
import { MaskField } from '@altricade/react-mask-field';

function App() {
  return <MaskField mask="(999) 999-9999" onChange={e => console.log(e.target.value)} />;
}

Specialized Components

Phone Input

import React, { useState } from 'react';
import { PhoneInput } from '@altricade/react-mask-field';

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

  return <PhoneInput countryCode="US" value={phone} onChange={e => setPhone(e.target.value)} />;
}

Date Input

import React from 'react';
import { DateInput } from '@altricade/react-mask-field';

function DateForm() {
  return (
    <DateInput
      format="MM/DD/YYYY"
      onChange={e => console.log(e.target.value)}
      enableDateValidation
    />
  );
}

Credit Card Input

import React, { useState } from 'react';
import { CreditCardInput, CardType } from '@altricade/react-mask-field';

function PaymentForm() {
  const [cardType, setCardType] = useState<CardType | null>(null);

  return (
    <div>
      <CreditCardInput
        onChange={e => console.log(e.target.value)}
        onCardTypeChange={setCardType}
        detectCardType
      />
      {cardType && <div>Card type: {cardType}</div>}
    </div>
  );
}

Time Input

import React from 'react';
import { TimeInput } from '@altricade/react-mask-field';

function TimeForm() {
  return <TimeInput format="12h" showSeconds onChange={e => console.log(e.target.value)} />;
}

API Documentation

MaskField Component

The core component that provides masking functionality.

Props

| Prop | Type | Default | Description | | ------------------------- | -------------------------------------------------------- | ----------- | ------------------------------------------------------- | | mask | string | (required) | Mask pattern for the input | | value | string | '' | The controlled input value | | maskChar | string | '_' | Character to cover unfilled parts of the mask | | formatChars | object | See below | Key-value map of format characters to RegExp strings | | beforeMaskedValueChange | (newState, oldState, userInput, maskOptions) => string | undefined | Function to modify the masked value before it's applied |

Default formatChars:

{
  '9': '[0-9]',
  'a': '[A-Za-z]',
  '*': '[A-Za-z0-9]'
}

Mask Format

The mask pattern supports the following format characters by default:

  • 9: Any numeric character (0-9)
  • a: Any alphabetic character (A-Z, a-z)
  • *: Any alphanumeric character (A-Z, a-z, 0-9)

Fixed characters in the mask (like parentheses, dashes, etc.) will be automatically inserted as the user types.

Implementation Details

  • Uses a simplified masking algorithm that properly restricts input based on the mask pattern
  • Supports different placeholder types (9 for digits, a for letters, * for alphanumeric)
  • Properly handles the maskChar property for placeholder generation
  • Maintains proper event handling for onChange callbacks
  • Filters out non-standard props from DOM elements to prevent React warnings

Examples

Phone Number

mask="(999) 999-9999"

This will format input as a US phone number like (123) 456-7890.

Credit Card

mask="9999 9999 9999 9999"

This will format input as a credit card number with spaces after every 4 digits.

Date

mask="99/99/9999"

This will format input as a date like 01/31/2023.

License

MIT