Skip to main content
Regexflux

Visa Card Number

beginner

Matches Visa credit card numbers (starts with 4, 13 or 16 digits).

credit-cardvisapaymentvalidation

Pattern

/4\d{3}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}/g

Try It

0 of 6 strings matched

Explanation

Matches Visa card numbers starting with 4, with 16 total digits optionally separated by spaces or hyphens in groups of 4.

Test Strings

Matching

  • 4111111111111111
  • 4111 1111 1111 1111
  • 4111-1111-1111-1111

Non-matching

  • 5111111111111111
  • 411111111111
  • 4111-111-111-1111

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /4\d{3}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns