目前用c#程序在谷歌搜索号码,把搜索描述中文本用
开源的google 号码识别库“libphonenumber”来判断文本文件是否包含电话号码
存在的问题:
需要增加一些号码规则
比如:6285755730687 判断是无效的
+6285755730687 增加了+判断是有效的
前面加了0或00判断都是无效的号码
06285755730687 或006285755730687都判断无效
验证地址:
https://catamphetamine.gitlab.io/libphonenumber-js/
下载地址:
https://github.com/google/libphonenumber
1没有+的正确号码判断无效6285755730687 无法识别
2添加了0或者00的代码判断06285755730687 无法识别
复制文本到https://catamphetamine.gitlab.io/libphonenumber-js/ 底部提示错误
No phone numbers found
需要帮忙重新编译libphonenumber,改JS源码,添加刚才的号码判断规则
去掉+ 6285755730687号码判断有效,
添加0或者00的号码判断有效06285755730687或006285755730687
请加V 186 8035 7299
对应正则表达式算法在 libphonenumber-master\resources的
PhoneNumberMetadata.xml和PhoneNumberAlternateFormats.xml
以下是程序调用libphonenumber的代码
function parsePhone(content: string) {
const numberFounds = findPhoneNumbersInText(content, 'US');
const phones: string[] = [];
for (const numberFound of numberFounds) {
phones.push(numberFound.number.number.toString().replace(/[+ -]/g, ''));
}
return phones;
}
你是要在一串文本里面识别出号码,是吗?
还是给一个指定的号码,判断是否有效?
哪种?
问题解决了吗?