Prompt
Write a program in Dart to check if a given string is a valid URL
Write a program in Dart to check if a given string is a valid URL
Sample response
Here's an example program in Dart to check if a given string is a valid URL using regular expressions:
```
void main() {
String url = 'https://www.example.com';
bool isValid = Uri.parse(url).isAbsolute;
if (isValid) {
print('$url is a valid URL');
} else {
print('$url is not a valid URL');
}
}
```
This program checks if the string `url` is a valid URL by parsing it with the `Uri` class and checking whether it is an absolute URI using the `isAbsolute` property. If `isAbsolute` returns `true`, then the URL is considered valid.
Published:
9 months ago