• Stars
    star
    730
  • Rank 59,900 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Masked <input/> React component

MaskedInput

A React component for <input> masking, built on top of inputmask-core.

This project has never been used by its author, other than while making it.

Live Demo

Install

npm

npm install react-maskedinput --save

Browser bundle

The browser bundle exposes a global MaskedInput variable and expects to find a global React variable to work with.

Usage

Give MaskedInput a mask and an onChange callback:

import React from 'react'
import MaskedInput from 'react-maskedinput'

class CreditCardDetails extends React.Component {
  state = {
    card: '',
    expiry: '',
    ccv: ''
  }

  _onChange = (e) => {
    this.setState({[e.target.name]: e.target.value})
  }

  render() {
    return <div className="CreditCardDetails">
      <label>
        Card Number:{' '}
        <MaskedInput mask="1111 1111 1111 1111" name="card" size="20" onChange={this._onChange}/>
      </label>
      <label>
        Expiry Date:{' '}
        <MaskedInput mask="11/1111" name="expiry" placeholder="mm/yyyy" onChange={this._onChange}/>
      </label>
      <label>
        CCV:{' '}
        <MaskedInput mask="111" name="ccv" onChange={this._onChange}/>
      </label>
    </div>
  }
}

Create some wrapper components if you have a masking configuration which will be reused:

function CustomInput(props) {
  return <MaskedInput
    mask="1111-WW-11"
    placeholder="1234-WW-12"
    size="11"
    {...props}
    formatCharacters={{
      'W': {
        validate(char) { return /\w/.test(char ) },
        transform(char) { return char.toUpperCase() }
      }
    }}
  />
}

Props

mask : string

The masking pattern to be applied to the <input>.

See the inputmask-core docs for supported formatting characters.

onChange : (event: SyntheticEvent) => any

A callback which will be called any time the mask's value changes.

This will be passed a SyntheticEvent with the input accessible via event.target as usual.

Note: this component currently calls onChange directly, it does not generate an onChange event which will bubble up like a regular <input> component, so you must pass an onChange if you want to get a value back out.

formatCharacters: Object

Customised format character definitions for use in the pattern.

See the inputmask-core docs for details of the structure of this object.

placeholderChar: string

Customised placeholder character used to fill in editable parts of the pattern.

See the inputmask-core docs for details.

value : string

A default value for the mask.

placeholder : string

A default placeholder will be generated from the mask's pattern, but you can pass a placeholder prop to provide your own.

size : number | string

By default, the rendered <input>'s size will be the length of the pattern, but you can pass a size prop to override this.

Other props

Any other props passed in will be passed as props to the rendered <input>, except for the following, which are managed by the component:

  • maxLength - will always be equal to the pattern's .length
  • onKeyDown, onKeyPress & onPaste - will each trigger a call to onChange when necessary

MIT Licensed

More Repositories

1

nwb

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)
JavaScript
5,562
star
2

react-hn

React-powered Hacker News client
JavaScript
2,174
star
3

control-panel-for-twitter

Browser extension which gives you more control over your Twitter timeline and adds missing features and UI improvements - available for desktop and mobile browsers
JavaScript
1,730
star
4

newforms

Isomorphic form-handling for React
JavaScript
642
star
5

msx

JSX for Mithril.js 0.x
JavaScript
362
star
6

react-heatpack

A 'heatpack' command for quick React development with webpack hot reloading
JavaScript
348
star
7

inputmask-core

Standalone input mask implementation, independent of any GUI
JavaScript
303
star
8

babel-plugin-react-html-attrs

Babel plugin which transforms HTML and SVG attributes on JSX host elements into React-compatible attributes
JavaScript
178
star
9

isomorphic-lab

Isomorphic React experimentation
JavaScript
144
star
10

DOMBuilder

DOM builder with multiple output formats
JavaScript
119
star
11

react-auto-form

Simplifies getting user input from forms via onChange and onSubmit events, using DOM forms APIs
JavaScript
116
star
12

react-router-active-component

Factory function for React components which are active for a particular React Router route
JavaScript
113
star
13

get-form-data

Gets form and field data via form.elements
JavaScript
106
star
14

react-lessons

Tool for creating and taking interactive React tutorials
JavaScript
102
star
15

react-examples

React… examples…
JavaScript
98
star
16

ad-hoc-reckons

JavaScript
85
star
17

remote_control_for_vlc

A VLC remote control written with Flutter
Dart
78
star
18

react-octicon

A GitHub Octicons icon React component
JavaScript
76
star
19

gatsby-plugin-dark-mode

A Gatsby plugin which handles some of the details of implementing a dark mode theme
JavaScript
68
star
20

react-filtered-multiselect

Filtered multi-select React component
JavaScript
61
star
21

redux-todomvc-es5

ES5 version of the Redux todomvc example
JavaScript
59
star
22

control-panel-for-youtube

Browser extension which gives you more control over YouTube by adding missing options and UI improvements - for desktop & mobile browsers
JavaScript
59
star
23

react-router-form

<Form> is to <form> as <Link> is to <a>
JavaScript
56
star
24

redux-action-utils

[DEPRECATED] Factory functions for reducing action creator boilerplate (pun not intended)
JavaScript
48
star
25

newforms-bootstrap

Components for rendering a newforms Form using Bootstrap 3
JavaScript
48
star
26

package-config-checker

Checks if your dependencies have package.json files config or an .npmignore for packaging
JavaScript
47
star
27

obs-bounce

OBS script to bounce a scene item around, DVD logo style or throw & bounce with physics
Lua
42
star
28

lifequote

React port of a life insurance quick quoting application
JavaScript
39
star
29

newforms-examples

Examples repository for newforms / React
JavaScript
32
star
30

ideas-md

A float-to-the-top ideas log built with React
JavaScript
32
star
31

react-gridforms

React components for Gridforms form layout
JavaScript
29
star
32

djangoffice

Project management/CRM for small offices - Clients, Jobs, Tasks, Rates, Activities, Timesheets, Contacts, Invoices etc. etc.
Python
28
star
33

tabata_timer

A Tabata training interval timer written with Flutter.
Dart
28
star
34

newforms-gridforms

Grid Forms integration for newforms
CSS
27
star
35

forum

A basic Django forum app with metaposts; uses redis for stats/tracking
Python
26
star
36

reactodo

Multiple localStorage TODO lists, built with React
JavaScript
25
star
37

react-plain-editable

[DEPRECATED] React component for editing plain text via contentEditable
JavaScript
21
star
38

comments-owl-for-hacker-news

Browser extension which makes it easer to follow comment threads on Hacker News across multiple visits, allows you to annotate and mute users, and other UI tweaks and mobile UX improvements
JavaScript
21
star
39

astro-lazy-youtube-embed

Embed YouTube videos with a static placeholder which only embeds when you click
Astro
17
star
40

ui-lib-samples

Misc impls of functionality with various JavaScript UI libs
HTML
15
star
41

gulp-msx

Precompile Mithril views which use JSX into JavaScript
JavaScript
14
star
42

soclone

The beginnings of a Stack Overflow clone
Python
14
star
43

react-dsl

Generate React components as DSLs for structural markup, such as that of CSS frameworks
CSS
14
star
44

manage-twitter-engagement

Manage "engagement" on Twitter by moving retweets and algorithmic tweets to their own lists
JavaScript
14
star
45

concur

Sugar for infectious JavaScript inheritance, metaprogramming & mixins
JavaScript
14
star
46

caveat-utilitor

Personal GtHub repo status badges
12
star
47

sublime-sort-javascript-imports

Sublime Text package for sorting selected JavaScript import/require() lines by module name
Python
11
star
48

hta-localstorage

Basic localStorage implementation for Internet Explorer HTML Applications (HTA)
JavaScript
11
star
49

greasemonkey

User scripts
JavaScript
11
star
50

nwb-from-create-react-app

Examples of using nwb as an alternative to ejecting from create-react-app
JavaScript
11
star
51

nwb-sass

Sass plugin for nwb
JavaScript
11
star
52

templates

Reusable templates for various kinds of projects
HTML
10
star
53

sacrum

One codebase, two environments - single-page JavaScript apps in the browser, forms 'n links webapps on Node.js for almost-free
JavaScript
10
star
54

isomorph

Shared utilities for browsers and Node.js
JavaScript
9
star
55

update-object

Mirror of Facebook's update() immutability helper
JavaScript
9
star
56

substitute

Edits Twitter typos using s/this/that/ expressions
JavaScript
7
star
57

react-playground

React component for creating interactive coding playgrounds with preset examples
JavaScript
7
star
58

dinnertime

Cooking timer & scheduler with spoken instructions
JavaScript
7
star
59

validators

Validators which can be shared between browsers and Node.js
JavaScript
7
star
60

sublime-react-snippets

Sublime Text snippets for writing React components
JavaScript
6
star
61

eslint-config-jonnybuchanan

Personal ESLint setup as a single devDependency
JavaScript
6
star
62

nwb-react-tutorial

An implementation of the React Tutorial using nwb's middleware
JavaScript
6
star
63

insin.github.io

Static project & demo hosting
JavaScript
6
star
64

react-objecteditor

An <ObjectEditor/> React component
JavaScript
5
star
65

nwb-thinking-in-react

An implementation of the Thinking in React tutorial using nwb
JavaScript
5
star
66

nwb-examples

Examples of configuring nwb
JavaScript
5
star
67

stargaze

Watch a GitHub repo's star count, with change notifications on your desktop
JavaScript
5
star
68

nwb-less

Less plugin for nwb
JavaScript
4
star
69

babel-preset-proposals

A Babel 7 preset to manage experimental proposal plugin dependencies and usage
JavaScript
4
star
70

urlresolve

Resolves paths against URL patterns
JavaScript
4
star
71

shilefare

Dead simple local, temporary file sharing with Node.js
JavaScript
4
star
72

couch25k

Java MIDlet which tracks intervals for the Couch-to-5k running program
Java
4
star
73

chainable-check

Create React.PropTypes-alike validators with an isRequired property
JavaScript
4
star
74

yak-stacker

An app for tracking your Yak Stack during programming sessions
4
star
75

deduped-babel-presets

[DEPRECATED] Babel 6 presets with shared dependencies manually deduplicated for npm2 compatibility
JavaScript
3
star
76

react-suggest

React components for implementing suggested completions
JavaScript
3
star
77

rllmuk-really-ignore-users

Really ignore ignored users, and ignore users in specific topics
JavaScript
3
star
78

react-split-date-input

Reusable split date input React component
JavaScript
3
star
79

njive

Node.js wrapper for the Jive API
JavaScript
3
star
80

bootstrap-4-nwb

Example app from "Using Bootstrap 4 from source with React and nwb"
CSS
3
star
81

react-node-time-tracker

A React clone of a Vue tutorial app
JavaScript
3
star
82

redbox-noreact

A fork of redbox-react which doesn't import React
JavaScript
3
star
83

POWDER-wii

Port files for the Wii version of POWDER ( http://www.zincland.com/powder/ )
C++
3
star
84

just-dadjokes

Just the jokes from /r/dadjokes
JavaScript
3
star
85

gulp-flatten-requires

Flattens relative require('./<path>/<module>') calls to require('./<module>')
JavaScript
3
star
86

cdogs-wii

Wii port of C-Dogs SDL using SDL Wii
C
3
star
87

event-listener

Simple function for addEventListener() vs. addEvent()
JavaScript
3
star
88

lmms

Linux MultiMedia Studio working directory
Python
3
star
89

pixel-shifter

A React component for pixel-shifting text elements
JavaScript
3
star
90

buildumb

Ultra-dumb exporter of Node.js modules for use in the browser
JavaScript
2
star
91

models

Models, models, everywhere. In the client and in the server.
JavaScript
2
star
92

mixinstance

Mix new things into an instance's prototype chain
JavaScript
2
star
93

django-vgdb

[OLD] Videogame database, opinion & story collector - begat django-mptt
Python
2
star
94

countdown-file

Writes a countdown to a text file every second
JavaScript
2
star
95

iswydt

Tumblejobs
JavaScript
2
star
96

cookdandbombd-really-ignore-users

Really ignore ignored users
JavaScript
2
star
97

twitter-searchite

Quick creation of sites driven by polling a Twitter search
JavaScript
2
star
98

stackoverflow

Code from investigating/answering StackOverflow questions
CSS
2
star
99

successcrm

JavaScript
2
star
100

rllmuk-ignore-topics

Hide topics and forums you're not interested in on the Rllmuk forum
JavaScript
2
star