All Projects → insin → React Maskedinput

insin / React Maskedinput

Licence: mit
Masked <input/> React component

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Maskedinput

React Day Picker
Date picker component for React
Stars: ✭ 4,374 (+524.86%)
Mutual labels:  react-component
React Contexify
Add a context menu to your react app with ease
Stars: ✭ 575 (-17.86%)
Mutual labels:  react-component
React Extras
Useful components and utilities for working with React
Stars: ✭ 651 (-7%)
Mutual labels:  react-component
React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (-36.71%)
Mutual labels:  react-component
React Compound Slider
◾️ React Compound Slider | A small React slider with no opinion on markup or styles
Stars: ✭ 553 (-21%)
Mutual labels:  react-component
React Text Loop
Animate words in your headings
Stars: ✭ 595 (-15%)
Mutual labels:  react-component
Chart Race React
📊 Seamless bar chart race component for React.
Stars: ✭ 406 (-42%)
Mutual labels:  react-component
React Awesome Query Builder
User-friendly query builder for React
Stars: ✭ 682 (-2.57%)
Mutual labels:  react-component
React Scrollbars Custom
The best React custom scrollbars component
Stars: ✭ 576 (-17.71%)
Mutual labels:  react-component
React Slider
Accessible, CSS agnostic, slider component for React.
Stars: ✭ 627 (-10.43%)
Mutual labels:  react-component
React Event Timeline
A responsive event timeline in React.js
Stars: ✭ 504 (-28%)
Mutual labels:  react-component
Uiw
⚛️ @uiwjs A high quality UI Toolkit, A Component Library for React 16+.
Stars: ✭ 531 (-24.14%)
Mutual labels:  react-component
Select
React Select
Stars: ✭ 609 (-13%)
Mutual labels:  react-component
Sunflower
🦹 Process components for antd4 & antd3 by alipay industry technology
Stars: ✭ 441 (-37%)
Mutual labels:  react-component
React S Alert
Alerts / Notifications for React with rich configuration options
Stars: ✭ 658 (-6%)
Mutual labels:  react-component
React Alice Carousel
React responsive component for building content galleries, content rotators and any React carousels
Stars: ✭ 419 (-40.14%)
Mutual labels:  react-component
Surmon.me.native
📱 My blog app, powered by react-native
Stars: ✭ 579 (-17.29%)
Mutual labels:  react-component
Awesome React Components
Curated List of React Components & Libraries.
Stars: ✭ 28,626 (+3989.43%)
Mutual labels:  react-component
React Input Range
React component for inputting numeric values within a range (range slider)
Stars: ✭ 680 (-2.86%)
Mutual labels:  react-component
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)
Stars: ✭ 5,429 (+675.57%)
Mutual labels:  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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].