您的位置:首页 > 理论基础 > 计算机网络

正则表达式验证HTTP地址是否合法

2016-09-23 13:52 295 查看
 public override void Checked()

        {

            string vInputName = “XXX”;

            string vValue = ObjectHelper.GetString(this.Value, vInputName);

           // object value = ObjectHelper.Get(this.Value, vInputName);

            string pattern = @"^(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([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}))(/[a-zA-Z0-9\&%_\./-~-]*)?$";

            //bool a = Regex.IsMatch(Convert.ToString(value), pattern);

            if (!Regex.IsMatch(vValue.Trim(), pattern))

            {

                string vFormat = this.SqlCheck.Format;

                string vTitle = this.GetTitle();

                if (string.IsNullOrEmpty(vFormat))

                {

                    vFormat = "[{0}]不符合HTTP地址格式!";

                }

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息