Home  >  Article  >  Backend Development  >  C# identifies whether url is a network path

C# identifies whether url is a network path

大家讲道理
大家讲道理Original
2016-11-10 14:53:011623browse

#region 识别urlStr是否是网络路径  
      /// <summary>  
      /// 识别urlStr是否是网络路径  
      /// </summary>  
      /// <param name="urlStr"></param>  
      /// <returns></returns>  
      public static bool UrlDiscern(string urlStr)  
      {  
          if (Regex.IsMatch(urlStr, @"((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?"))  
          {  
              return true;  
          }  
          else 
          {  
              return false;  
          }  
      }  
      #endregion

Statement:
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