getCardTypeFrmNumber method

CardType getCardTypeFrmNumber(
  1. String input
)

Implementation

static CardType getCardTypeFrmNumber(String input) {
  CardType cardType;
  if (input.startsWith(new 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(new RegExp(r'[4]'))) {
    cardType = CardType.Visa;
  } else if (input
      .startsWith(new RegExp(r'((506(0|1))|(507(8|9))|(6500))'))) {
    cardType = CardType.Verve;
  } else if (input.startsWith(new RegExp(r'((34)|(37))'))) {
    cardType = CardType.AmericanExpress;
  } else if (input.startsWith(new RegExp(r'(6011|65|64[4-9]|622[1-9])'))) {
    cardType = CardType.Discover;
  } else if (input
      .startsWith(new RegExp(r'((30[0-5])|(3[89])|(36)|(3095))'))) {
    cardType = CardType.DinersClub;
  } else if (input.startsWith(new RegExp(r'(352[89]|35[3-8][0-9])'))) {
    cardType = CardType.Jcb;
  } else if (input.startsWith(new RegExp(
      r'(5018|5081|5044|504681|504993|5020|502260|5038|603845|603123|6304|6759|676[1-3]|6220|504834|504817|504645|504775)'))) {
    cardType = CardType.Maestro;
  } else if (input.startsWith(new RegExp(r'3[47]'))) {
    cardType = CardType.Amex;
  } else if (input.startsWith(new RegExp(
      r'(508227|508[5-9]|603741|60698[5-9]|60699|607[0-8]|6079[0-7]|60798[0-4]|60800[1-9]|6080[1-9]|608[1-4]|608500|6521[5-9]|652[2-9]|6530|6531[0-4])'))) {
    cardType = CardType.Rupay;
  } else if (input.length <= 8) {
    cardType = CardType.Others;
  } else {
    cardType = CardType.Invalid;
  }
  return cardType;
}