https://github.com/sindresorhus/ip-regex

    • ip-regex - Regular expression for matching IP addresses
    • is-cidr - Check if a string is an IP address in CIDR notation
    • cidr-regex - Regular expression for matching IP addresses in CIDR notation ```jsx npm install ip-regex

    import ipRegex from ‘ip-regex’;

    export function isIP(string) { return ipRegex({exact: true}).test(string); }

    export function isIPv6(string) { return ipRegex.v6({exact: true}).test(string); }

    export function isIPv4(string) { return ipRegex.v4({exact: true}).test(string); }

    export function ipVersion(string) { return isIP(string) ? (isIPv6(string) ? 6 : 4) : undefined; }

    // test isIP(‘1:2:3:4:5:6:7:8’); //=> true

    isIP(‘192.168.0.1’); //=> true

    isIPv4(‘1:2:3:4:5:6:7:8’); //=> false

    ipVersion(‘abc’); //=> undefined ```