Home > Web Front-end > JS Tutorial > How to confirm whether the URL or email address in the text is genuine

How to confirm whether the URL or email address in the text is genuine

php中世界最好的语言
Release: 2018-04-26 17:43:17
Original
2772 people have browsed it

这次给大家带来怎样确认文本里url或邮件地址是否为真,确认文本里url或邮件地址为真的注意事项有哪些,下面就是实战案例,一起来看一下。

这段代码可以分析出文本里的所有超级链接,包含邮件、url、#链接等等,并分别输出为真实链接地址

$.fn.tweetify = function() {
 this.each(function() {
  $(this).html(
   $(this).html()
    .replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>')
    .replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>')
    .replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>')
  );
 });
 return $(this);
}
Copy after login

用法:

$("p").tweetify();
Copy after login

原始文本:

<p>@seanhood have you seen this http://icanhascheezburger.com/ #lol</p>
Copy after login

分析以后:

<p><a href="http://twitter.com/seanhood">@seanhood</a> have you seen this
<a href="http://icanhascheezburger.com/">http://icanhascheezburger.com/</a>
<a href="http://search.twitter.com/search?q=%23lol">#lol</a></p>
Copy after login

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

jquery操作动画显示与隐藏效果效果

jQuery选项卡切换特效实现步骤

The above is the detailed content of How to confirm whether the URL or email address in the text is genuine. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template