can some one tell me how can i validate a url like http://www.abc.com
Uri.IsWellFormedUriString checks that the URL format is correct and does not require escaping.
///
/// Ensures the property is a valid URL.
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class ValidateUrlAttribute : ValidationAttribute
{
public ValidateUrlAttribute()
{
}
public override bool IsValid(object value)
{
// Do not validate missing URLs - people can use [Required] for that.
string text = (value as string) ?? "";
if (text == "")
return true;
return Uri.IsWellFormedUriString(text, UriKind.Absolute);
}
}