removeSpacesAndHyphens function

String? removeSpacesAndHyphens(
  1. String? cardNumberWithSpaces
)

Converts a card number that may have spaces between the numbers into one without any spaces. Note: method does not check that all characters are digits or spaces.

@param cardNumberWithSpaces a card number, for instance "4242 4242 4242 4242" @return the input number minus any spaces, for instance "4242424242424242". Returns {@code null} if the input was {@code null} or all spaces.

Implementation

String ? removeSpacesAndHyphens(String? cardNumberWithSpaces) {
  if (cardNumberWithSpaces ==null|| isBlank(cardNumberWithSpaces)) {
    return null;
  }
  return cardNumberWithSpaces.replaceAll(RegExp(r"\s+|\-+"), "");
}