Android examples for java.util.regex:IP Address Pattern
is string a Valid IP Address
import java.text.DateFormat; import java.text.ParseException; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static boolean isIPAddressValid(String IPAddress) { boolean isValid = false; Pattern pattern = Pattern .compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); Matcher matcher = pattern.matcher(IPAddress); if (matcher.matches()) { isValid = true;/*from ww w. j a va2 s .c o m*/ } return isValid; } }