Look directly at the code:
ImportJava.util.regex.Pattern; Public classApp {Private Staticpattern pattern; Private StaticPattern Ptipv4; Static { //IPv6 Pattern = Pattern.compile ("^ (([0-9a-fa-f]{1,4}:) {7}[0-9a-fa-f]{1,4}) | ( ([0-9a-fa-f]{1,4}:) {1,7}:) | ( ([0-9a-fa-f]{1,4}:) {6}:[0-9a-fa-f]{1,4}) | (([0-9a-fa-f]{1,4}:) {5} (: [0-9a-fa-f]{1,4}) {]) | (([0-9a-fa-f]{1,4}:) {4} (: [0-9a-fa-f]{1,4}) {1,3}) | (([0-9a-fa-f]{1,4}:) {3} (: [0-9a-fa-f]{1,4}) {1,4}) | (([0-9a-fa-f]{1,4}:) {2} (: [0-9a-fa-f]{1,4}) {1,5}) | ([0-9a-fa-f]{1,4}:(: [0-9a-fa-f]{1,4}] {1,6}) | (:(: [0-9a-fa-f]{1,4}) {1,7}) | (([0-9a-fa-f]{1,4}:) {6} (\\d|[ 1-9]\\D|1\\D{2}|2[0-4]\\D|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])) {3}) | (([0-9a-fa-f]{1,4}:) {5}:(\\d|[ 1-9]\\D|1\\D{2}|2[0-4]\\D|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])) {3}) | (([0-9a-fa-f]{1,4}:) {4} (: [0-9a-fa-f]{1,4}) {0,1}:(\\d|[ 1-9]\\D|1\\D{2}|2[0-4]\\D|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])) {3}) | (([0-9a-fa-f]{1,4}:) {3} (: [0-9a-fa-f]{1,4}) {0,2}:(\\d|[ 1-9]\\D|1\\D{2}|2[0-4]\\D|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])) {3}) | (([0-9a-fa-f]{1,4}:) {2} (: [0-9a-fa-f]{1,4}) {0,3}:(\\d|[ 1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])) {3}) | ([0-9a-fa-f]{1,4}:(: [0-9a-fa-f]{1,4}] {0,4}:(\\d|[ 1-9]\\D|1\\D{2}|2[0-4]\\D|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])) {3}) | (:(: [0-9a-fa-f]{1,4}) {0,5}:(\\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])) {3})) $ "); //IPv4Ptipv4 = Pattern.compile ("^ (\\d|[ 1-9]\\D|1\\D{2}|2[0-4]\\D|25[0-5]) (\ \. ( \\d| [1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]) {3}$ ")); } Public Static voidMain (string[] args) {System.out.println (Pattern.matcher ("2001:0DB8:0000:0023:0008:0800:200C:417A"). Matches ()); System.out.println (Pattern.matcher ("2001:DB8:0:23:8:800:200C:417A"). Matches ()); System.out.println (Pattern.matcher ("2001:db8:0:23:8:800:192.1.0.0"). Matches ()); System.out.println (Pattern.matcher ("2001:db8:0::800:192.1.0.0"). Matches ()); System.out.println (Pattern.matcher ("2001:db8:0:23::192.1.0.0"). Matches ()); System.out.println (Pattern.matcher (":: 192.1.0.0"). Matches ()); System.out.println (Pattern.matcher ("1:af::3"). Matches ()); System.out.println (Pattern.matcher ("1:af::"). Matches ()); System.out.println (Pattern.matcher (":: 1:af:0"). Matches ()); System.out.println (Pattern.matcher (":: 0"). Matches ()); System.out.println ("---------------------"); System.out.println (Pattern.matcher ("+2001:0DB8:0000:0023:0008:0800:200C:417A"). Matches ()); System.out.println (Pattern.matcher ("2001:0DB8:0Z00:0023:0008:0800:200C:417A"). Matches ()); System.out.println (Pattern.matcher ("2001:db8:0:23:800::192.1.0.0.1"). Matches ()); System.out.println (Pattern.matcher ("2001:db8::23::800:192.1.0.0"). Matches ()); System.out.println (Pattern.matcher (":::"). Matches ()); System.out.println (Pattern.matcher ("1:::2"). Matches ()); System.out.println ("---------------------"); System.out.println (Ptipv4.matcher ("1.1.0.1"). Matches ()); System.out.println (Ptipv4.matcher ("123.1.0.19"). Matches ()); System.out.println (Ptipv4.matcher ("255.255.255.255"). Matches ()); System.out.println (Ptipv4.matcher ("0.0.0.0"). Matches ()); System.out.println ("---------------------"); System.out.println (Ptipv4.matcher (" -1.1.0.1"). Matches ()); System.out.println (Ptipv4.matcher ("1.1b.0.1"). Matches ()); System.out.println (Ptipv4.matcher ("1.01.0.1"). Matches ()); System.out.println (Ptipv4.matcher ("1.1.300.1"). Matches ()); System.out.println (Ptipv4.matcher ("1.1..1"). Matches ()); }}
Java uses regular expressions to determine if it is a valid Ipv4ipv6 address