javascript - 处理手机号码中的连续号码
问题描述
在我的 react-native 应用程序中,我想验证手机号码。所以我使用了 google-libphonenumber 库。
现在有一个要求,避免手机号码中的连续号码。例如:在新加坡,没有国家代码的手机号码有 8 位数字。在这里,我们不应该有 7 个相同数字的连续数字。
+65 81111111
这应该是错误的。
如何使用 google-libphonenumber 库验证这一点?这是我的验证码。
/** mobile with country code */
const mobileWithCode = (value: any) => {
const regex = /^[+](\d){8,13}$/;
if (regex.test(value)) {
try {
const phoneNumberUtil = PhoneNumberUtil.getInstance();
const mobile = phoneNumberUtil.parseAndKeepRawInput(value, '');
const phoneType = phoneNumberUtil.getNumberType(mobile);
if (phoneType === PhoneNumberType.MOBILE) {
console.log(PhoneNumberType.TOLL_FREE);
return phoneNumberUtil.isValidNumber(mobile);
}
return false;
} catch (err) {
return false;
}
}
return false;
};
解决方案
推荐阅读
- python - 带有 numpy 随机集的奇怪 FFT 图
- filenet-p8 - 在 FileNet P8 中以编程方式将一个文件夹归档到另一个文件夹下
- c++ - std::dec、std::hex、std::oct 的二进制模拟
- amazon-web-services - EFS 会在实例终止后维护文件吗?
- javascript - 在 Google Apps 脚本中异步保存复选框
- powershell - 在表结构上添加 where-object?
- kotlin - kotlin - 如何在 Parceable 中创建一个可为空的布尔值
- pandas - 将不同权重的 DataFrame 列相乘
- android - 使用导航控制器android从一个方向导航到另一个方向时无法实例化片段?
- gmail - Gmail“+”号技巧,现在他们要求我从“+”号地址发送请求