Link Search Menu Expand Document

Short IPv6 Regexp

PHP preg_match() example

IPv6 Regexp:


If you’re interested in seeing some more IPv6 regex examples for other languages you should check this link Shortest IPv6 Validation Regular Expression (RegEx).

Here is the source, a better way of matching IPv6 using PHP preg_match()

function valid_ipv6_address( $ipv6 )
    $regex = '/^(((?=(?>.*?(::))(?!.+3)))3?|([dA-F]{1,4}(3|:(?!$)|$)|2))(?4){5}((?4){2}|(25[0-5]|(2[0-4]|1d|[1-9])?d)(.(?7)){3})z/i';
        if(!preg_match($regex, $ipv6))
        return (false); // is not a valid IPv6 Address

    return (true);