CVV/CVC Regex

^[0-9]{3,4}$

Validate CVV/CVC security codes: 3 digits for most cards, 4 digits for American Express.

Test This Pattern →

Pattern Breakdown

Understanding the regex pattern ^[0-9]{3,4}$:

  • ^ - Start of string
  • $ - End of string
  • [...] - Character class
  • {n,m} - Quantifier (n to m times)

Examples

Input Result Explanation
123 ✓ Match Standard 3-digit CVV
1234 ✓ Match Amex 4-digit CID
12 ✗ No Match Too short

Code Examples

JavaScript

JavaScript
const pattern = /^[0-9]{3,4}$/;
const text = "123";

// Test if string matches
if (pattern.test(text)) {
  console.log("Valid!");
}

// Extract matches
const matches = text.match(pattern);
console.log(matches);

Python

Python
import re

pattern = r'^[0-9]{3,4}$'
text = "123"

# Test if string matches
if re.match(pattern, text):
    print("Valid!")

# Find all matches
matches = re.findall(pattern, text)
print(matches)

PHP

PHP
<?php
$pattern = '/^[0-9]{3,4}$/';
$text = "123";

// Test if string matches
if (preg_match($pattern, $text)) {
    echo "Valid!";
}

// Find all matches
preg_match_all($pattern, $text, $matches);
print_r($matches);
?>

Java

Java
import java.util.regex.*;

String pattern = "^[0-9]{3,4}$";
String text = "123";

Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(text);

if (m.matches()) {
    System.out.println("Valid!");
}

Use Cases

Common applications: Payment forms, card verification

Frequently Asked Questions

What is the regex pattern for cvv/cvc regex?
The regex pattern is: ^[0-9]{3,4}$. Validate CVV/CVC security codes: 3 digits for most cards, 4 digits for American Express.
How do I use the cvv/cvc regex pattern in JavaScript?
In JavaScript: const regex = new RegExp('^[0-9]{3,4}$'); or const regex = /^[0-9]{3,4}$/;
Does this pattern work in Python?
Yes, use: import re; pattern = re.compile(r'^[0-9]{3,4}$') in Python. Most regex patterns are cross-language compatible.
What are common use cases for cvv/cvc regex?
Payment forms, card verification

Related Regex Patterns

More Regex Tools

GetDevUtils offers a suite of developer tools including: