https://github.com/lemoncode/fonk-is-credit-card-validator
Is credit card validator for https://github.com/Lemoncode/fonk
https://github.com/lemoncode/fonk-is-credit-card-validator
Last synced: 9 months ago
JSON representation
Is credit card validator for https://github.com/Lemoncode/fonk
- Host: GitHub
- URL: https://github.com/lemoncode/fonk-is-credit-card-validator
- Owner: Lemoncode
- License: mit
- Created: 2019-09-11T14:43:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-07T09:09:04.000Z (over 6 years ago)
- Last Synced: 2025-05-08T01:44:04.687Z (about 1 year ago)
- Language: TypeScript
- Size: 25.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fonk-is-credit-card-validator
[](https://circleci.com/gh/Lemoncode/fonk-is-credit-card-validator/tree/master)
[](https://www.npmjs.com/package/@lemoncode/fonk-is-credit-card-validator)
[](https://bundlephobia.com/result?p=@lemoncode/fonk-is-credit-card-validator)
This is a [fonk](https://github.com/Lemoncode/fonk) microlibrary that brings validation capabilities to:
- Validate if a field of a form is a valid credit card
How to install it:
```bash
npm install @lemoncode/fonk-is-credit-card-validator --save
```
How to add it to an existing form validation schema:
We have the following form model:
```
const myFormValues = {
clientId: 1,
creditCard: '375556917985515'
}
```
We can add a isCreditCard validation to the myFormValues
```javascript
import { isCreditCard } from '@lemoncode/fonk-is-credit-card-validator';
const validationSchema = {
field: {
creditCard: [isCreditCard.validator],
},
};
```
You can customize the error message displayed in two ways:
- Globally, replace the default error message in all validationSchemas (e.g. porting to spanish):
```javascript
import { isCreditCard } from '@lemoncode/fonk-is-credit-card-validator';
isCreditCard.setErrorMessage(
'El valor debe de ser un número de tarjeta de crédito válido'
);
```
- Locally just override the error message for this validationSchema:
```javascript
import { isCreditCard } from '@lemoncode/fonk-is-credit-card-validator';
const validationSchema = {
field: {
creditCard: [
{
validator: isCreditCard.validator,
message: 'Error message only updated for the validation schema',
},
],
},
};
```
Please, refer to [fonk](https://github.com/Lemoncode/fonk) to know more.
## License
[MIT](./LICENSE)
# About Basefactor + Lemoncode
We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.
[Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services.
[Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services.
For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend