Java examples for java.util.regex:Match IP Address
is Valid IP Address by regex
//package com.java2s; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { String address = "java2s.com"; System.out.println(isValidAddress(address)); }/*from w w w .j av a2 s .c o m*/ private static final String IPADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; public static boolean isValidAddress(String address) { if (address == null) { return false; } return Pattern.compile(IPADDRESS_PATTERN).matcher(address) .matches(); } }