如何为英国电话号码编写正则表达式 [英] How to write a regular expression for UK phone numbers
本文介绍了如何为英国电话号码编写正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的任务是在页面中找到电话号码并用一个标签包裹它们。它需要找到各种不同的手机格式,所以请选择一个灵活而全面的正则表达式。
例子 -
0116 2746 190
0116 2746190
079155 24272
b / b
+44 78904 12345
1234567890
(0800)123 456
我试过下面的代码,它没有工作..请帮助
$(document).ready(function(){
var regex = /((\(\\\ { 3 } \)?)|(\d { 3 } - ))?\d {< span class =code-digit> 3 } - \d { 4 } / g;
var text = $( body:first)。html() ;
text = text.replace(regex, & lt; a href = \tel:$& \> $&< / a>);
$( body:first)。wrap(text);
});
解决方案
(document).ready(function(){
var regex = /((\(\\\ { 3 } \)?)|(\d {< span class =code-digit> 3 } - ))?\d { 3 } - \d { 4 } / g;
var text =
( body:first)。html();
text = text.replace(regex, < a href = \tel:
& \>
I got a task to find phone numbers in the page and wraps them with an a tag . It needs to find a variety of different phone formats so please choose a regex that is flexible and comprehensive.
Examples -
0116 2746 190
0116 2746190
079155 24272
+44 78904 12345
1234567890
(0800) 123 456
I've tried with below code, its not working.. Please help
$(document).ready(function () {
var regex = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/g;
var text = $("body:first").html();
text = text.replace(regex, "<a href=\"tel:$&\">$&</a>");
$("body:first").wrap(text);
});
解决方案
(document).ready(function () { var regex = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/g; var text =
("body:first").html(); text = text.replace(regex, "<a href=\"tel:
&\">
这篇关于如何为英国电话号码编写正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文