我正在尝试查找两个电话号码是否相同(两个相同的电话号码可能格式不同,因为+919998245345999824534599982 45345相同)

最佳答案

为此,可以使用contains() Dart 字符串方法。我将尾随语句标记为粗体,因为它适用于String。确保以字符串格式获取数字,或将其转换为字符串,然后执行操作。
Alogrithm

代码

// this is a comparision between +919998245345 and other numbers
// you can play around and get what you want
void main() {
  var _inputPhone = "+919998245345";
  var _checkPhone = "9998245345";
  var _anotherCheck = "99982 45345";

  // checking that white space removal works or not
  print(_anotherCheck.replaceAll(new RegExp(r"\s+"), ""));

  // I have just removed the spaces from the number which had the white
  // space, you can store the value using this code for every data
  // for unknown data coming from server side or user side
  _anotherCheck = _anotherCheck.replaceAll(new RegExp(r"\s+"), "");
  if(_inputPhone.contains(_anotherCheck)){
    print('99982 45345 and +919998245345 are same');
  }

  if(_inputPhone.contains(_checkPhone)){
    print('9998245345 and +919998245345 are same');
  }

}
输出
9998245345
99982 45345 and +919998245345 are same
9998245345 and +919998245345 are same

10-01 21:20