Socket
Book a DemoInstallSign in
Socket

react-masked-field

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-masked-field

A masked field component built in React

2.1.3
latest
Source
npmnpm
Version published
Weekly downloads
6.8K
-42.78%
Maintainers
3
Weekly downloads
 
Created
Source

React Masked Field Build Status

A masked field component built in React.

The MaskedField component is a text input field that allows you to restrict and format the values that can be entered into it, while informing the user of the expected input. Common uses include dates, phone numbers, social security numbers and tax IDs.

Example

import MaskedField from 'react-masked-field';

ReactDOM.render(
  <MaskedField mask="99/99/9999" onComplete={() => console.log('Date is ' + date)} />,
  document.getElementById('demo'),
);

Installation

Install from npm:

npm install react-masked-field

Props

mask?: string

The mask applied to the value of the field. For each character of the mask that matches a translation, the input character will be restricted to the corresponding regular expression. If no mask is provided, it will function like a normal input element.

translations?: { [char: string]: RegExp }

default:

{
  '9': /\d/,
  'a': /[A-Za-z]/,
  '*': /[A-Za-z0-9]/
}

Additional (or overridden) translations for converting mask characters to regular expressions.

onComplete?: (val: string) => void

The onComplete event is triggered when the mask has been completely filled. The value of the field is passed to the event handler.

inputRef?: (node: HTMLInputElement | null) => any

A ref passed to the internal input element.

placeholder?: string

default: the value of the mask prop

This functions just like a normal input placeholder prop. If no placeholder is provided, the mask prop will be used as the placeholder.

Other props

In addition to the props above, MaskedField should handle all supported input props.

License

This project is licensed under the terms of the MIT license

Keywords

react

FAQs

Package last updated on 30 Dec 2024

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.