parseAndKeepRawInput method

PhoneNumber parseAndKeepRawInput(
  1. String numberToParse,
  2. String? defaultRegion
)

Parses a string and returns it in proto buffer format. This method differs from parse in that it always populates the rawInput field of the protocol buffer with numberToParse as well as the countryCodeSource field.

numberToParse number that we are attempting to parse. This can contain formatting such as +, ( and -, as well as a phone number extension. defaultRegion region that we are expecting the number to be from. This is only used if the number being parsed is not written in international format. The country calling code for the number in this case would be stored as that of the default region supplied. return PhoneNumber a phone number proto buffer filled with the parsed number. throws NumberParseException if the string is not considered to be a viable phone number or if no default region was supplied.

Implementation

PhoneNumber parseAndKeepRawInput(
    String numberToParse, String? defaultRegion) {
  if (!_isValidRegionCode(defaultRegion)) {
    if (numberToParse.isNotEmpty && numberToParse[0] != plusSign) {
      throw NumberParseException(ErrorType.invalidCountryCode);
    }
  }
  return _parseHelper(numberToParse, defaultRegion, true, true);
}