valid URL check in csharp

Code Example - valid URL check in csharp

                
                        public static bool CheckURLValid(this string source) => Uri.TryCreate(source, UriKind.Absolute, out Uri uriResult) && uriResult.Scheme == Uri.UriSchemeHttps;
                    
                
 

valid url in .net

                        
                                //Try this to validate HTTP URLs (url is the URI you want to test):
//
	// Checks how well a url validator does against a known list of valid and invalid Urls
	// The sample urls here are from http://formvalidation.io/validators/uri
	//	
// test 
/// in text this only one that most low (17) error
public static bool UrlChecker5(string url)
	{
		Uri uriResult;
		bool result = Uri.TryCreate(url, UriKind.Absolute, out uriResult) 
			&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
       return result;
	}
// and than (17)

public static bool UrlChecker2(string url)
	{
		return Uri.IsWellFormedUriString(url, UriKind.Absolute);
	}
// if we combine both with like UrlChecker5(url) && UrlChecker2(url)
// error become lowest 15 error
                            
                        
 

Related code examples