jaumard / sms_autofill

Flutter plugin to provide SMS code autofill support
MIT License
281 stars 173 forks source link

How do i get only the phone number and not the country code or how can i extracct the phone number from this response? #198

Open shabanaqureshi opened 1 year ago

shabanaqureshi commented 1 year ago

Hello, I am using the following library to extract the phone number of the user. I want to enable auto filling of mobile number, I am using the PhoneFieldHint library, am able to get the phone number with the country code, but i want to get only the phone number. Question: How do i get only the phone number and not the country code or how can i extracct the phone number from this response?

LakshayDCoder commented 9 months ago

I also had the same problem so I just extracted the last 10 digits of the string that I got from the autofil hint. Below is the code for the same.

phoneController.text = extractLast10Digits(phone);

  String extractLast10Digits(String input) {
    String digitsOnly = input.replaceAll(RegExp(r'[^0-9]'), '');
    if (digitsOnly.length >= 10) {
      return digitsOnly.substring(digitsOnly.length - 10);
    } else {
      return digitsOnly;
    }
  }