一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

js 验证url 是否正确

时间:2010-09-12 编辑:简简单单 来源:一聚教程网

本文章提供一款完美的 js 验证url 是否正确代码,他可以验证现在所有域名,如cc,hk,me,pro等url正则验证表达式函数。

function isvalidurl( chars ) {
 // chars = chars.replace(',',"");
 //var re=/^([hh][tt]{2}[pp]://|[hh][tt]{2}[pp][ss]://)((((w+(-*w*)+).)+((com)|(net)|(edu)|(gov)|(org)|(biz)|(aero)|(coop)|(info)|(name)|(pro)|(museum))(.([a-z]{2}))?)|((w+(-*w*)+).(cn)))$/;
 var re=/^([hh][tt]{2}[pp]://|[hh][tt]{2}[pp][ss]://)(s+.s+)$/;
 //var re=/^([hh][tt]{2}[pp]://|[hh][tt]{2}[pp][ss]://)(((((w+(-*w*)+).)+((com)|(net)|(edu)|(gov)|(org)|(biz)|(aero)|(coop)|(info)|(name)|(pro)|(me)|(cc)|(museum)|(cn)|(tv)|(hk))(.([a-z]{2}))?)|((w+(-*w*)+).(cn)))((/|?)s*)*)$/;
 if (!isnull(chars)) {
  chars = jstrim(chars);
  if (chars.match(re) == null)
   return false;
  else
   return true;
 }
 return false;
}

热门栏目