isValid() function
Whether a string is a valid IPv4 or IPv6 address.
Signature:
export declare function isValid(ip: string): boolean;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
ip |
string |
the string to test |
Returns:
boolean
true for a valid address of either family.
Remarks
Node's own net.isIP, so it accepts a bare address only — '', 'unknown' and '10.0.0.0/8' are all false, because a prefix length makes it a CIDR record rather than an address. Use this to screen untrusted input before Networks, whose constructor throws on anything it cannot parse.
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.