toDigitWithPlus static method

String? toDigitWithPlus(
  1. String? value
)

Converts a string to contain only digits and a plus sign.

Example: '123abc!@#' -> '123+'

Implementation

static String? toDigitWithPlus(String? value) {
  if (value == null || value.isEmpty) return null;
  String buffer = '';
  for (String character in value.characters) {
    if (character == '+' || Validator.isDigit(character)) {
      buffer = '$buffer$character';
    }
  }
  return buffer;
}