平台严格禁止发布违法/不实/欺诈等垃圾信息,一经发现将永久封禁帐号,针对违法信息将保留相关证据配合公安机关调查!
<script>
//检测手机号并给手机号添加链接
var circleList;
var isPhone = /\d{11}/g;
circleList = $(".content").html();
var arrPhone = circleList.match(isPhone);
console.log(arrPhone);
circleList = circleList.replace(isPhone, function(word) {
return '<a href="tel:' + word + '">' + word + '</a>';
})
$(".content").html(circleList);
只检测手机号用上述链接即可!
/*检测固定电话、手机号码、邮箱并且添加链接*/
function content(value) {
/*固定电话、手机号码、邮箱*/
var tempValue = value.replace(/<[^>]+>/g, "");
var arrMatch = tempValue.match(/[0-9a-z][0-9a-z\-\_\.]+@([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}|0[0-9]{2,3}-{0,1}[2-9][0-9]{6,7}|[0-9]+/g);
//按长度排序,避免被提前替换
for (var i = 0; i < arrMatch.length; i++) {
for (var j = i + 1; j < arrMatch.length; j++) {
if (arrMatch[i].length < arrMatch[j].length) {
var tmp = arrMatch[i];
arrMatch[i] = arrMatch[j];
arrMatch[j] = tmp;
}
}
}
for (var match in arrMatch) {
var t = arrMatch[match];
var replacev = '';
//邮箱
if (/^[0-9a-z][0-9a-z\-\_\.]+@([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}$/.test(t)) {
replacev = '<a href="javascript:;" οnclick="event.stopPropagation();mailto:' + t + '">' + t + '</a>';
}
//固定电话
if (/^0[0-9]{2,3}-{0,1}[2-9][0-9]{6,7}$/.test(t)) {
replacev = '<a href="javascript:;" οnclick="event.stopPropagation();tel:' + t + '">' + t + '</a>';
}
//手机号码
else if (/^1[34578]\d{9}$/.test(t) || /^\d{7,8}$/.test(t)) {
replacev = '<a href="javascript:;" οnclick="event.stopPropagation();tel:' + t + '">' + t + '</a>';
}
else {
}
var reg = new RegExp("(?!<a .*?>.*?)" + t + "(?![^<]*<\/a>)", "gmi");
value = value.replace(reg, replacev);
}
return value;
}
</script>