Validationflags: g

Credit Card Number

Match 16-digit credit card numbers with optional spaces or hyphens between groups of 4.

Try it in RegexPro

Pattern

regexJavaScript
/\b(?:\d{4}[\s\-]?){3}\d{4}\b/g

Raw source: \b(?:\d{4}[\s\-]?){3}\d{4}\b

How it works

Three groups of 4 digits with optional space/hyphen separators, followed by a final 4-digit group. Word boundaries prevent partial matches.

Examples

Input

4111 1111 1111 1111

Matches

  • 4111 1111 1111 1111

Input

4111-1111-1111-1111

Matches

  • 4111-1111-1111-1111

Input

4111111111111111

Matches

  • 4111111111111111

Common use cases

  • PCI-DSS data discovery scans
  • Detecting card numbers in logs (for masking)
  • Payment form validation
  • Data loss prevention (DLP) tools
All patternsTest this pattern live →