❔ What's the best way to test a URL that's it's valid?
I have a situation where the user can enter a URL if they so choose, but if they do, I want to ensure it's valid. How would I do that? Should I use a regular expression test or something else? Normally, this will be a website on the Internet in my case.
4 Replies
Somewhat depends on "valid" but this might be what you're looking for https://learn.microsoft.com/en-us/dotnet/api/system.uri.trycreate?view=net-7.0&redirectedfrom=MSDN#System_Uri_TryCreate_System_String_System_UriKind_System_Uri__
Uri.TryCreate Method (System)
Creates a new Uri. Does not throw an exception if the Uri cannot be created.
OK. Thanks.
This can get very complex fast, for example https://learn.microsoft.com/en-us/dotnet/api/system.globalization.idnmapping?view=net-7.0
IdnMapping Class (System.Globalization)
Supports the use of non-ASCII characters for Internet domain names. This class cannot be inherited.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.