Back to Home

Credit Card Validation Regex (American Express)

CronOS Team
regexcredit-cardvalidationtutorialamexpayment

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern

Credit Card Validation Regex (American Express)

Validate American Express credit card numbers starting with 34 or 37 and having 15 digits using regex pattern.

Pattern Breakdown

regex
^3[47][0-9]{13}$

Components

ComponentDescriptionMatches
^Start anchorEnsures match from string start
3Amex prefixMust start with 3
[47]Second digitMust be 4 or 7 (34 or 37)
[0-9]{13}Remaining digitsExactly 13 more digits (15 total)
$End anchorEnsures match to string end

Character Classes

  • 3 - Literal 3 (Amex starts with 3)
  • [47] - Second digit: 4 or 7 (34 or 37)
  • [0-9] - Any digit 0-9
  • {13} - Quantifier: exactly 13 occurrences

Examples

Valid:

  • 341111111111111 (starts with 34, 15 digits)
  • 371111111111111 (starts with 37, 15 digits)
  • 340000000000000 (starts with 34)
  • 379999999999999 (starts with 37)

Invalid:

  • 4111111111111111 (starts with 4, Visa)
  • 351111111111111 (starts with 35, not Amex)
  • 34111111111111 (only 14 digits)
  • 3411111111111111 (16 digits)
  • 3-4111-1111-1111-111 (contains formatting)

Implementation

JavaScript

javascript
const amexRegex = /^3[47][0-9]{13}$/;
amexRegex.test('341111111111111'); // true
amexRegex.test('371111111111111'); // true
amexRegex.test('4111111111111111'); // false (Visa)
amexRegex.test('351111111111111'); // false (not Amex range)

// To handle formatted numbers, remove formatting first
const formatted = '3411-111111-11111'.replace(/[-\s]/g, '');
amexRegex.test(formatted); // true

Python

python
import re
amex_regex = r'^3[47][0-9]{13}$'
bool(re.match(amex_regex, '341111111111111'))  # True
bool(re.match(amex_regex, '371111111111111'))  # True
bool(re.match(amex_regex, '4111111111111111'))  # False (Visa)

# To handle formatted numbers
formatted = '3411-111111-11111'.replace('-', '').replace(' ', '')
bool(re.match(amex_regex, formatted))  # True

Go

go
amexRegex := regexp.MustCompile(`^3[47][0-9]{13}$`)
amexRegex.MatchString("341111111111111") // true
amexRegex.MatchString("371111111111111") // true
amexRegex.MatchString("4111111111111111") // false (Visa)

Limitations

  1. No Luhn algorithm: Doesn't validate using Luhn checksum algorithm
  2. No formatting: Doesn't accept formatted numbers (spaces, dashes)
  3. Format only: Validates format, not actual card validity
  4. No expiration/CVV: Doesn't validate expiration date or CVV
  5. Security: Never store full card numbers, only last 4 digits
  6. Fixed length: Only validates 15-digit Amex cards

When to Use

  • Initial format validation
  • Quick card type detection
  • Client-side validation (first pass)
  • When you need to identify Amex cards

For production, consider:

  • Implementing Luhn algorithm for checksum validation
  • Supporting formatted input (remove spaces/dashes)
  • Using payment processing libraries (Stripe, PayPal, etc.)
  • Never storing full card numbers
  • Server-side validation (never trust client-side only)
  • PCI DSS compliance requirements

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern