can some one tell me how can i validate a url like http://www.abc.com
Here is proper validation attribute code used in prod system:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class UriValidation : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null || value.ToString() == string.Empty)
{
return true;
}
try
{
Uri result;
if (Uri.TryCreate(value.ToString(), UriKind.RelativeOrAbsolute, out result))
{
if (result.Scheme.StartsWith("http") || result.Scheme.StartsWith("https"))
{
return true;
}
}
}
catch
{
return false;
}
return false;
}
}