credit-card-regex
Regular expression for matching credit card numbers
Install
$ npm install credit-card-regex
Usage
const creditCardRegex = require('credit-card-regex');
creditCardRegex().test('6011881485017922 foo bar');
creditCardRegex({exact: true}).test('6011881485017922 foo bar');
creditCardRegex({exact: true}).test('6011881485017922');
'foo 6011881485017922 bar 5441068611005540'.match(creditCardRegex());
API
creditCardRegex(options)
Returns a regex for matching credit card numbers. It supports credit card numbers from the following vendors:
- American Express
- Diners Club
- Discover
- JCB
- Maestro
- MasterCard
- VISA
options
exact
Type: Boolean
Default: false
(Matches any credit card number in a string)
Only match an exact string. Useful with RegExp#test
to check if a string is a credit card number.
License
MIT © Kevin Mårtensson