Hi all,
I’m junior developer, so I ‘m not yet pick up Regular Expressions (>o<).
In current situation, I want to check SharePoint URL is valid or not, and my simple coding as follows:
if (strTargetASPX.Substring(0, 4).ToLower().Equals("http") &&
strTargetASPX.Substring(strTargetASPX.Length - 4, 4).ToLower().Equals("aspx") &&
strTargetASPX.IndexOf("!") < 0 &&
strTargetASPX.IndexOf("@") < 0 &&
strTargetASPX.IndexOf("#") < 0 &&
strTargetASPX.IndexOf("$") < 0 &&
strTargetASPX.IndexOf("^") < 0 &&
strTargetASPX.IndexOf("*") < 0 &&
strTargetASPX.IndexOf("(") < 0 &&
strTargetASPX.IndexOf(")") < 0 &&
strTargetASPX.IndexOf("-") < 0 &&
strTargetASPX.IndexOf("+") < 0 &&
strTargetASPX.IndexOf(@"\") < 0 &&
strTargetASPX.IndexOf("\"") < 0 &&
strTargetASPX.IndexOf(";") < 0 &&
strTargetASPX.IndexOf("|") < 0 &&
strTargetASPX.IndexOf("[") < 0 &&
strTargetASPX.IndexOf("]") < 0 &&
strTargetASPX.IndexOf("{") < 0 &&
strTargetASPX.IndexOf("}") < 0 &&
strTargetASPX.IndexOf("`") < 0
)
{
//Do something
}
But I’m not sure the above checking is exactly correct or not, therefore, I would like to get your advice for best practices.
I tried to use Regular Expression, but all example url cannot match RgxUrl ...Orz
================Code 1:================
//"pattern " Source from http://www.regexplib.com/Resources.aspx
string pattern = @" ^(?=[^&])(?:(?<scheme>[^:/?#]+):)?(?://(?<authority>[^/?#]*))?(?<path>[^?#]*)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))? ";
Regex RgxUrl = new Regex(examplURL);
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
Regex RgxUrl = new Regex(examplURL);
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
Could you please help me?
//"pattern " Source from http://www.regexplib.com/Resources.aspx
string pattern = @" ^(?=[^&])(?:(?<scheme>[^:/?#]+):)?(?://(?<authority>[^/?#]*))?(?<path>[^?#]*)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))? ";
Regex RgxUrl = new Regex(examplURL);
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
Regex RgxUrl = new Regex(examplURL);
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
if(RgxUrl.IsMatch(examplURL)
{
}
================Example Url List:================
Could you please help me?
Thank you very much .^^