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

<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, "");

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:


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

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

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

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: