Overview
Check if the string is a valid URL. Validates http and https protocols with configurable TLD, wildcard, fragment, and query string options.
Import
import {validators} from 'metronic-extension';
const {isURL} = validators;
Signature
isURL(value: string, options?: IsURLOptions): boolean
| Parameter |
Type |
Default |
Description |
value |
string |
- |
Value to be validated. |
options.requireFQDNTld |
boolean |
true |
If true, the TLD is required. |
options.allowFQDNWildcard |
boolean |
false |
If true, allows domain starting with *. (e.g. *.example.com). |
options.allowFragments |
boolean |
false |
If true, allow fragment input (e.g. #section). |
options.allowQueryComponents |
boolean |
false |
If true, allow query string input (e.g. ?key=value). |
Returns: boolean — true if valid, false otherwise.
Example
<div class="mb-3">
<label class="form-label">Input value</label>
<input id="isURLInput" class="form-control form-control-solid" placeholder="Enter a URL..." value="https://www.example.com/">
</div>
<div>
<span class="fw-bold">Result: </span>
<span id="isURLResult" class="badge badge-success">true</span>
</div>
var isURL = metronicExtension.validators.isURL;
var input = document.getElementById('isURLInput');
var result = document.getElementById('isURLResult');
function update() {
var valid = isURL(input.value);
result.textContent = valid ? 'true' : 'false';
result.className = 'badge ' + (valid ? 'badge-success' : 'badge-danger');
}
input.addEventListener('input', update);
update();