Documentation v4.0.0

Overview

Check for a fully qualified domain name (e.g. domain.com) or IP (version 4 or 6). Combines isFQDN and isIP validation.

Import

import {validators} from 'metronic-extension';
const {isFQDNOrIP} = validators;

Signature

isFQDNOrIP(value: string, options?: IsFQDNOrIPOptions): 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.ipVersion '4' | '6' | 4 | 6 undefined IP version to validate. If omitted, allows both IPv4 and IPv6.
options.allowIPRange boolean false If true, allow IP range input (e.g. 127.0.0.1/24, 2001::/128).
Returns: booleantrue if valid, false otherwise.

Example

Result: true
<div class="mb-3">
  <label class="form-label">Input value</label>
  <input id="isFQDNOrIPInput" class="form-control form-control-solid" placeholder="Enter a domain or IP address...">
</div>
<div>
  <span class="fw-bold">Result: </span>
  <span id="isFQDNOrIPResult" class="badge"></span>
</div>
import {validators} from 'metronic-extension';
const {isFQDNOrIP} = validators;

// Domain names
isFQDNOrIP('domain.com');                                 // true

// IPv4
isFQDNOrIP('127.0.0.1');                                  // true
isFQDNOrIP('1.2.3.4', {ipVersion: 4});                    // true

// IPv6
isFQDNOrIP('2001:db8:0000:1:1:1:1:1');                    // true
isFQDNOrIP('::ffff:127.0.0.1', {ipVersion: 6});           // true