JavaScript 中的电话号码识别
有没有可以识别网页中电话号码的javascript库?就像 Skype 在他们的 Firefox 插件上所做的那样。
或者您知道如何做到这一点的方法吗?具有相同功能的网站或任何教程都会非常有帮助。
非常感谢您的回复。
最好的,
Is there a javascript library the can recognize phone numbers in a web page? Just like what skype did on their firefox plugin.
Or do you know a way on how to do it? Websites or any tutorial that do the same would be very helpful.
Your reply is greatly appreciated.
Best,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
其他人可能有更好的方法来做到这一点,但这似乎为您提供了每个电话号码的链接。
我只是使用了简单的正则表达式,因此您可能需要替换 Adam 提供的正则表达式。
希望有帮助。
编辑:
在此版本中它可能也能正常工作,甚至更好。
我不知道是否有任何陷阱,但似乎适用于一个相当简单的页面。
Someone else may have a better way of doing this, but this seems to give you a link around each phone number.
I just used my simple regular expression, so you may want to substitute the one that Adam provided.
Hope it helps.
EDIT:
It may work as well, or better, with this version.
I don't know if there are any pitfalls, but seems to work with a fairly simple page.
要查找字符串中的匹配项,您需要使用正则表达式。这个(虽然有点长)效果很好:(
找到这里)
这将匹配“2405525009”、“1(240) 652-5009”和“240/752-5009 ext.55”,但不是“(2405525009”或“2 (240) 652-5009”。
要查找所有匹配项,您可以想要在
while
循环中重复应用exec()
方法,如 此处。To find matches within a string, you'll want to use a regular expression. This one (although somewhat lengthy) works pretty well:
(found here)
This will match "2405525009", "1(240) 652-5009", and "240/752-5009 ext.55", but not "(2405525009" or "2 (240) 652-5009".
To find all matches, you may want to repeatedly apply the
exec()
method in awhile
loop, as seen here.