Detect credit card numbers in an email
This article explains how to detect an email containing something that looks like a credit card number.
- Visit your USS Dashboard and click Products ⟶ E-mail Security ⟶ Custom Rule Data.
- Click to create a new Rule RegEx.
- Give it a sensible name such as Credit Card numbers and click
- Left-click your new Rule to edit it.
- For Visa Cards, enter the following pattern in the value field:
\b4\d{3}([\ \-]?)\d{4}\1\d{4}\1\d{4}\b(?!([^<]+)?>)
- Click
- Switch to the Message Rules tab.
- Create a new Rule called Credit Cards.
- Add a Body or Subject Condition, with the value set to Matches: Credit Card numbers.
- Add your desired Action or Final Action, and click
Custom Rule Data for other credit card types
The example given above will detect Visa cards. The following RegEx patterns can be used to detect other credit card types. You'll need to create a new Custom Rule Data for each one.
Mastercard
\b5[1-5]\d{2}([\ \-]?)\d{4}\1\d{4}\1\d{4}\b(?!([^<]+)?>)
Discover or Diners
\b6(?:011|22(?:1(?=[\ \-]?(?:2[6-9]|[3-9]))|[2-8]|9(?=[\ \-]?(?:[01]|2[0-5])))|4[4-9]\d|5\d\d)([\ \-]?)\d{4}\1\d{4}\1\d{4}\b(?!([^<]+)?>)
JCB (China)
\b35(?:2[89]|[3-8]\d)([\ \-]?)\d{4}\1\d{4}\1\d{4}\b(?!([^<]+)?>)
American Express
\b(?<!\-|\.)3[47]\d\d([\ \-]?)(?<!\d\ \d{4}\ )(?!(\d)\2{5}|123456|234567|345678)\d{6}(?!\ \d{5}\ \d)\1(?!(\d)\3{4}|12345|56789)\d{5}(?!\-)(?!\.\d)\b(?!([^<]+)?>)