Jone_Sun

关于验证网址的正则表达式

C#:

//首先要引用System.Text.RegularExpressions;命名空间
//然后要声明表达式的规则,这个规则适用于http,https,ftp等开头的网址形式
 string s_reg = @"((http|https|ftp):(\/\/|\\\\)((\w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)";

//然后得到要匹配的字符串
            string url=this.txt_url.Text.Trim();
//声明一个regex
            Regex reg=new Regex(s_reg);
//然后是做匹配
            if (!reg.IsMatch(url))
            {
//这是ajax的提示方式
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", "<script language=\'javascript\'>alert(\'提示\\n链接地址格式不正确!\');document.all(\'txt_url\').focus()</script>", false);
                return;
            }

 

分类:

技术点:

相关文章:

  • 2018-01-30
  • 2021-11-08
  • 2021-11-04
  • 2021-10-06
  • 2021-11-12
  • 2021-11-04
猜你喜欢
  • 2021-11-24
  • 2021-10-06
  • 2021-11-24
  • 2021-10-06
  • 2021-11-23
  • 2021-12-03
  • 2021-10-06
相关资源
相似解决方案