Credit Card Pattern

Credit Card Number Regex Tester

Validate credit card numbers with regular expressions

Example Credit Card Pattern:
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$
41111111111111115500000000000004378282246310005

Regex Flags

Click flags to toggle them on/off
//g
49 characters
4111111111111111 5500000000000004 378282246310005

No matches found

Pattern Explanation

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$

No explanation available

About Credit Card Regex Patterns

Credit card validation combines format checking with mathematical verification (Luhn algorithm). Regex handles the format: correct length, valid prefix for card type, and proper digit grouping. The Luhn check confirms the number is mathematically valid.

Our credit card regex tester helps you recognize card types and validate format before processing payments.

Why Validate Credit Cards?

Early card validation improves UX and reduces payment failures. Catching typos before submission saves users from failed transaction messages and potential holds on their accounts.

Card type detection (Visa starts 4, Mastercard 51-55 or 2221-2720, Amex 34/37) enables showing the appropriate card logo, building user confidence their input is recognized correctly.

Building the Pattern

Card-specific patterns:

Visa: ^4[0-9]{12}(?:[0-9]{3})?$ (13 or 16 digits, starts with 4) Mastercard: ^5[1-5][0-9]{14}$ (16 digits, starts with 51-55) Amex: ^3[47][0-9]{13}$ (15 digits, starts with 34 or 37)

A combined pattern matches any major card type. Always follow with Luhn validation.

Common Use Cases

  • Checkout form validation
  • Card type auto-detection
  • Payment form UX enhancement
  • Data format verification

Pro Tip

Never rely solely on regex—always use the Luhn algorithm. And of course, never store raw card numbers; use tokenization via your payment processor.

Other Regex Patterns