@shaaditech/react-cc-validator
Version:
Credit/Debit card number validation library with input formatting
72 lines (53 loc) • 1.82 kB
Markdown
# react-cc-validator
Credit/Debit card number validator input written in react.
[Demo](https://phenax.github.io/react-cc-validator)
[](https://travis-ci.org/phenax/react-cc-validator)
[](https://codecov.io/gh/phenax/react-cc-validator)
[](http://npmjs.com/package/@shaaditech/react-cc-validator)
[](https://greenkeeper.io/)
### Install
* Add package in project using
`yarn add @shaaditech/react-cc-validator`
* Import
```js
import CardNumberValidator from '@shaaditech/react-cc-validator';
```
### API
#### Usage
You can refer to [/example](https://github.com/phenax/react-cc-validator/tree/master/example/src)
```js
const YourComponent = () => (
<div>
<CardNumberValidator>
{({ isValid, cardType, getInputProps }) => (
<div>
<input type="text" {...getInputProps()} />
<div>{ isValid && cardType }</div>
{isValid || <div>Card number is invalid</div>}
</div>
)}
</CardNumberValidator>
</div>
);
```
#### Types
```js
// The props that can be passed to CardNumberValidator compopent
type PropTypes = {
children: PassedProps => ReactNode,
validCardTypes: Array<String>,
format: Boolean,
};
// The props to be passed to the input element
type InputProps = {
onChange: Function,
value: String,
};
// The props passed down to the render component
type PassedProps = {
...InputProps,
isValid: Boolean,
cardType: String,
getInputProps: () => InputProps,
};
```