isValidURL
Check if a string is a valid URL.
Installation
pnpm dlx shadcn@latest add https://reactusekit.dev/r/is-valid-url.json
Usage
import { isValidURL } from "@/lib/is-valid-url";
function App() {
const validURL = "https://example.com";
const invalidURL = "not-a-url";
return (
<div>
<p>
{validURL}: {isValidURL(validURL) ? "Valid" : "Invalid"}
</p>
<p>
{invalidURL}: {isValidURL(invalidURL) ? "Valid" : "Invalid"}
</p>
</div>
);
}
API
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
url | string | - | The URL string to validate |
options | object | {} | Configuration options |
Returns
Type | Description |
---|---|
boolean | True if the URL is valid, false otherwise |