isValid static method

bool isValid(
  1. String card, [
  2. dynamic stripBeforeValidation = true
])

Implementation

static bool isValid(String card, [stripBeforeValidation = true]) {
  if (stripBeforeValidation) {
    card = strip(card);
  }
  if (card.isEmpty) {
    return false;
  }
  if (card.length < minLength || card.length > maxLength) {
    return false;
  }
  if (!RegExp(r'^\d+$').hasMatch(card)) {
    return false;
  }
  if (RegExp(r'^(\d)\1+$').hasMatch(card)) {
    return false;
  }
  return _luhnCheck(card);
}