getCardTypeFrmNumber static method

CardType? getCardTypeFrmNumber(
  1. String input
)

Implementation

static CardType? getCardTypeFrmNumber(String input) {
  if (input.isEmpty) {
    return null;
  }
  CardType? cardType;
  if (input.startsWith(RegExp(
      r'((5[1-5])|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720))'))) {
    cardType = CardType.master;
  } else if (input.startsWith(RegExp(r'[4]'))) {
    cardType = CardType.visa;
  } else if (input.startsWith(RegExp(r'((34)|(37))'))) {
    cardType = CardType.americanExpress;
  } else if (input.startsWith(RegExp(r'((6[45])|(6011))'))) {
    cardType = CardType.discover;
  } else if (input.startsWith(RegExp(r'((30[0-5])|(3[89])|(36)|(3095))'))) {
    cardType = CardType.dinersClub;
  } else if (input.startsWith(RegExp(r'(352[89]|35[3-8][0-9])'))) {
    cardType = CardType.jcb;
  } else if (input.startsWith(RegExp(r'(220[0-4])'))) {
    cardType = CardType.mir;
  } else if (input.startsWith(RegExp(r'(62|81)'))) {
    cardType = CardType.unionPay;
  } else if (input.length <= 8) {
    cardType = CardType.others;
  } else {
    cardType = CardType.invalid;
  }
  return cardType;
}