Network & IP Validators

Network validators for IP addresses, URL parsing, query parameters, and API endpoint validation.

17 code snippets available

Is Private IP

network

Checks if IP is in private range.

#ip#security
ts
const isPrivateIP = (ip: string): boolean => {
  const parts = ip.split('.').map(Number);
  return parts[0] === 10 || (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) || (parts[0] === 192 && parts[1] === 168);
};

Parse URL

network

Parses URL into components.

#url#parse
ts
const parseURL = (url: string) => new URL(url);

Get Query Params

network

Extracts query parameters from URL.

#url#query
ts
const getQueryParams = (url: string): Record<string, string> => Object.fromEntries(new URL(url).searchParams);

IPv4

network

Standard IP address.

#ip
ts
const isValid = (s: string): boolean => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(s);

IPv6

network

Standard IPv6.

#ip
ts
const isValid = (s: string): boolean => /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::1)$/.test(s);

MAC Address

network

Hardware ID.

#hardware
ts
const isValid = (s: string): boolean => /^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/.test(s);

Domain Name

network

Valid domain (no protocol).

#domain#web
ts
const isValid = (s: string): boolean => /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/.test(s);

Subdomain

network

Valid subdomain format.

#domain#web
ts
const isValid = (s: string): boolean => /^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/.test(s);

FTP URL

network

FTP protocol URL.

#ftp#url
ts
const isValid = (s: string): boolean => /^ftp:\/\/[^\s]+$/.test(s);

Port Number

network

Valid port (1-65535).

#port#network
ts
const isValid = (s: string): boolean => /^([1-9]\d{0,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/.test(s);

CIDR Notation

network

IP range notation.

#ip#network
ts
const isValid = (s: string): boolean => /^([0-9]{1,3}\.){3}[0-9]{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/.test(s);

IP Range

network

IP address range.

#ip#range
ts
const isValid = (s: string): boolean => /^([0-9]{1,3}\.){3}[0-9]{1,3}-([0-9]{1,3}\.){3}[0-9]{1,3}$/.test(s);

Bluetooth MAC

network

Bluetooth address.

#bluetooth#hardware
ts
const isValid = (s: string): boolean => /^([0-9A-F]{2}:){5}[0-9A-F]{2}$/.test(s);

WiFi SSID

network

Valid SSID name.

#wifi#network
ts
const isValid = (s: string): boolean => /^[^\/\\\x00-\x1f]{1,32}$/.test(s);

IPv4 with Port

network

IP address with port.

#ip#port
ts
const isValid = (s: string): boolean => /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]{1,5}$/.test(s);

WebSocket URL

network

WS/WSS protocol URL.

#websocket#protocol
ts
const isValid = (s: string): boolean => /^wss?:\/\/[^\s]+$/.test(s);

SSH URL

network

SSH protocol URL.

#ssh#protocol
ts
const isValid = (s: string): boolean => /^ssh:\/\/[^\s]+$/.test(s);

About Network & IP Validators

Our network & ip validation snippets are designed to handle the most common validation scenarios you'll encounter in modern software development. Each snippet is thoroughly tested, optimized for performance, and follows industry best practices.

All validators are available in multiple programming languages including JavaScript, TypeScript, Python, Go, PHP, C#, and Rust. Simply copy the code snippet, adapt it to your specific needs, and integrate it into your project. Every snippet is MIT licensed—free for personal and commercial use.

Browse Other Categories