File tree Expand file tree Collapse file tree
apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,6 +129,27 @@ class PhoneUtils @Inject constructor(
129129 }
130130 }
131131
132+ /* *
133+ * Parse an international phone number (e.g. "+15551234567") into its country locale
134+ * and national number digits. Returns null if parsing fails.
135+ */
136+ fun parseInternationalNumber (number : String ): Pair <CountryLocale , String >? {
137+ val cleaned = number.filter { it.isDigit() || it == ' +' }
138+ if (cleaned.isBlank() || ! cleaned.startsWith(" +" )) return null
139+
140+ return try {
141+ val parsed = phoneNumberUtil.parse(cleaned, defaultCountryLocale.countryCode)
142+ if (! phoneNumberUtil.isValidNumber(parsed)) return null
143+
144+ val regionCode = phoneNumberUtil.getRegionCodeForNumber(parsed) ? : return null
145+ val locale = countryLocales.find { it.countryCode == regionCode } ? : return null
146+ val nationalNumber = parsed.nationalNumber.toString()
147+ locale to nationalNumber
148+ } catch (_: NumberParseException ) {
149+ null
150+ }
151+ }
152+
132153 fun toE164 (rawNumber : String ): String? {
133154 val cleaned = rawNumber.filter { it.isDigit() || it == ' +' }
134155 if (cleaned.isBlank()) return null
You can’t perform that action at this time.
0 commit comments