Skip to content

Instantly share code, notes, and snippets.

View fnk0's full-sized avatar

Marcus Gabilheri fnk0

  • Snap
  • Los Angeles, CA
View GitHub Profile
@fnk0
fnk0 / CardType.java
Created March 25, 2018 06:14 — forked from gabrielbauman/CardType.java
A Java enum representing credit card types (Visa, Mastercard etc) that can detect card type from a credit card number.
package com.gabrielbauman.gist;
import java.util.regex.Pattern;
public enum CardType {
UNKNOWN,
VISA("^4[0-9]{12}(?:[0-9]{3}){0,2}$"),
MASTERCARD("^(?:5[1-5]|2(?!2([01]|20)|7(2[1-9]|3))[2-7])\\d{14}$"),
AMERICAN_EXPRESS("^3[47][0-9]{13}$"),