is a string representing an IP Address by regex - Android java.net

Android examples for java.net:IP Address

Description

is a string representing an IP Address by regex

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.regex.Pattern;

public class Main{

    public static boolean isIPAddress(String ip) {
        if (ip.matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"))
            return true;
        else {//w ww . j a  v a  2  s . c o m
            return false;
        }
    }

}

Related Tutorials