javascript - Linkyfing european phone number -
i searching regex replaces random phone number <a href>
. phone numbers should swedish, non-swedish should supported.
i support following formats:
(0 + 9 numbers)
- +46xxxxxxxxx
- 0046xxxxxxxxx
- 0xxxxxxxxx
(0 + 8 numbers)
- +46xxxxxxxx
- 0046xxxxxxxx
- 0xxxxxxxx
(0 + 7 numbers)
- +46xxxxxxx
- 0046xxxxxxx
- 0xxxxxxx
usually formatted according format this page, have no requirement support (although great).
what have tried far, tried lot of regex. using this answer tried make own version of it, can't seem work. closest have come regex, yet removes much:
/( |^|>)((((\+|00)[0-9]{2} ?(\(0\))?)|0)([0-9]{2}-? ?[0-9]{7})|([0-9]{3}-? ?[0-9]{6})|([0-9]{1}-? ?[0-9]{8}))( |$|<)/gi
this fiddle: http://jsfiddle.net/xaxy4/1/
the goal of script identify phone numbers , make them <a href="tel:xxx">xxx</a>
link. current code is:
$(document).ready(function () { var patt=/( |^|>)((((\+|00)[0-9]{2} ?(\(0\))?)|0)([0-9]{2}-? ?[0-9]{7})|([0-9]{3}-? ?[0-9]{6})|([0-9]{1}-? ?[0-9]{8}))( |$|<)/gi $('*','body').each(function() { $(this).html($(this).html().replace(patt,'<a href="tel:$2">$2</a>')); }); });
the following seems capture pretty allowed formats in test page.
pattern: /([^\d\+]|^|>)((((\+|00)(\d\d)\s*(\(0\))?)|0)(\s*\d){7,9})([^\d\+]|$|<)/gi replace: '$1<a href="tel:$2">$2</a>$9'
Comments
Post a Comment