Android IP Address Check isIp4Address(String text)

Here you can find the source of isIp4Address(String text)

Description

is Ip Address

Declaration

public static boolean isIp4Address(String text) 

Method Source Code

//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.text.TextUtils;

public class Main {
    public static final String regIpAddress = "^([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 isIp4Address(String text) {
        if (TextUtils.isEmpty(text)) {
            return false;
        }/*from  w  ww.  j a  v  a  2s. c o m*/

        Pattern pattern = Pattern.compile(regIpAddress);
        Matcher macher = pattern.matcher(text);
        return macher.matches();
    }

    public static boolean isEmpty(String text) {
        if (text == null || text.length() == 0) {
            return true;
        }
        return false;
    }
}

Related

  1. isSipAddress(String numberOrAddress)
  2. isStrictSipAddress(String numberOrAddress)