Skip to content

regexhq/credit-card-regex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

credit-card-regex Build Status

Regular expression for matching credit card numbers

Install

$ npm install --save credit-card-regex

Usage

var creditCardRegex = require('credit-card-regex');

creditCardRegex().test('6011881485017922 foo bar');
//=> true

creditCardRegex({exact: true}).test('6011881485017922 foo bar');
//=> false

creditCardRegex({exact: true}).test('6011881485017922');
//=> true

'foo 6011881485017922 bar 5441068611005540'.match(creditCardRegex());
//=> ['6011881485017922', '5441068611005540']

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

About

Regular expression for matching credit card numbers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%