Credit Card Number
🔒 SecurityValidates major credit card numbers (Visa, MasterCard, Amex, Discover).
Regex Pattern
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$✓ Matches
41111111111111115500000000000004340000000000009
✗ Does Not Match
1234567890123456411111111111abcd1234efgh5678
Code Examples
1const regex = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$/;2const str = '4111111111111111';34// Test if string matches5const isMatch = regex.test(str);6console.log('Match found:', isMatch);78// Find all matches (add 'g' flag for multiple matches)9const matches = str.match(regex);10console.log('Matches:', matches);1112// Find matches with details13let match;14const regexWithGlobal = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$/g;15while ((match = regexWithGlobal.exec(str)) !== null) {16 console.log('Match:', match[0], 'Index:', match.index);17}
About Credit Card Number Regular Expression
This regex pattern is designed to validates major credit card numbers (visa, mastercard, amex, discover).. It can be used in JavaScript, Python, PHP, Java, and other programming languages that support regular expressions.
How to Use This Pattern
- Copy the regex pattern above
- Use the "Try in Tester" button to test it with your own data
- Use the code generator to get implementation code in your preferred language
Pattern Breakdown
Understanding each part of this regex will help you modify it for your specific needs. Click the "Explanation" tab in the tester to see a detailed breakdown of each component.