Clickable phone number BBCode

Started by Chen Zhen, May 20, 2018, 04:46:34 pm

Previous topic - Next topic

Chen Zhen

name: phone
description: Call this number
type: [tag]{content}[/tag]
parsing: {content} only

Code Select
<script type="text/javascript">
var tel_id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
document.write('<div style="display: inline;" id="' + tel_id + '"></div>');
var link = document.createElement("a");
var tel_number1 = "{content}";
var tel_number2 = tel_number1;
var view_filter = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/g;
var tel_filter = /\D/g;
var tel_type = "tel://";
link.textContent = tel_number1.replace(view_filter, "");
link.href = tel_type + tel_number2.replace(tel_filter, "");
document.getElementById(tel_id).appendChild(link);
</script>

The regex in these variables can be altered:
view_filter -> what is displayed to members
tel_filter -> the number used in the clickable link

the type of call can also be altered:
tel_type -> ie. use "callto://" or "tel://"




other possible regex filter examples:

re. DISPLAY

U.S./Canada phone numbers ~ display:
Code Select
var view_filter = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;




re. CLICKABLE LINK
International ~ link filter:
Code Select
var tel_filter = /[\s()+\-\.]|ext/gi;

Code Select
var tel_filter = /^\+[0-9]?()[0-9](\s|\S)(\d[0-9]{9})$/gm;

Code Select
var tel_filter = /^[+]?([0-9]*[\.\s\-\(\)]|[0-9]+){3,24}$/gm;




If someone can reference a single javascript file phone number filter (using a jQuery library is fine) then I will test it and possibly include it in this example.

ref support thread: https://web-develop.ca/index.php?topic=239.0

milenyals