正則表示式驗證HTTP地址是否合法
阿新 • • 發佈:2019-02-10
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地址格式!";
}
}
}
{
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地址格式!";
}
}
}