toPhoneValue static method

int? toPhoneValue(
  1. dynamic phone
)

Numeric phone for analytics events, or null when it can't be determined. int.tryParse(phone ?? '0') ?? 0 is not used because it reports a missing phone as 0.

Implementation

static int? toPhoneValue(dynamic phone) {
  final digits = '${phone ?? ''}'
      .replaceAll(RegExp(r'[\s-]'), '')
      .replaceFirst(RegExp(r'^\+91'), '');
  // Whole-string check so "98-76abc" is rejected rather than truncated.
  return RegExp(r'^\d+$').hasMatch(digits) ? int.tryParse(digits) : null;
}