isURLValid
Check if a string is a valid URL.
Installation
npx react-usekit@latest init
Select: utils → TypeScript or JavaScript → path -> isURLValid
Usage
import { isURLValid } from "./utils/isURLValid";
function App() {
const validURL = "https://example.com";
const invalidURL = "not-a-url";
return (
<div>
<p>
{validURL}: {isURLValid(validURL) ? "Valid" : "Invalid"}
</p>
<p>
{invalidURL}: {isURLValid(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 |