Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
react-maskedinput
Advanced tools
MaskedInput
A React component for <input>
masking, built on top of inputmask-core.
MaskedInput
can be used on the server, or bundled for the client using an npm-compatible packaging system such as Browserify or webpack.
npm install react-maskedinput --save
The browser bundle exposes a global MaskedInput
variable and expects to find a global React
(>= 0.14.0) variable to work with.
You can find it in the /dist directory.
Give MaskedInput
a mask
and an onChange
callback:
var React = require('react')
var MaskedInput = require('react-maskedinput')
var CreditCardDetails = React.createClass({
state: {
card: '',
expiry: '',
ccv: ''
},
_onChange(e) {
var stateChange = {}
stateChange[e.target.name] = e.target.value
this.setState(stateChange)
},
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:
var CustomInput = React.createClass({
render() {
return <MaskedInput
mask="1111-WW-11"
placeholder="1234-WW-12"
size="11"
{...this.props}
formatCharacters={{
'W': {
validate(char) { return /\w/.test(char ) },
transform(char) { return char.toUpperCase() }
}
}
}/>
}
})
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.
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 necessary3.1.0 / 2016-02-11
value
behaving as a controlled component.FAQs
Masked React component
The npm package react-maskedinput receives a total of 13,212 weekly downloads. As such, react-maskedinput popularity was classified as popular.
We found that react-maskedinput demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.