public static boolean isValidIPv4(String address){
  if (address.length() == 0) {
    return false;
  }
  int octet;
  int octets=0;
  String temp=address + ".";
  int pos;
  int start=0;
  while (start < temp.length() && (pos=temp.indexOf('.',start)) > start) {
    if (octets == 4) {
      return false;
    }
    try {
      octet=Integer.parseInt(temp.substring(start,pos));
    }
 catch (    NumberFormatException ex) {
      return false;
    }
    if (octet < 0 || octet > 255) {
      return false;
    }
    start=pos + 1;
    octets++;
  }
  return octets == 4;
}

public static boolean isValidIPv4 ( String address ) { if ( address . length ( ) == 0 ) { return false ; } int octet ; int octets = 0 ; String temp = address + "." ; int pos ; int start = 0 ; while ( start < temp . length ( ) && ( pos = temp . indexOf ( '.' , start ) ) > start ) { if ( octets == 4 ) { return false ; } try { octet = Integer . parseInt ( temp . substring ( start , pos ) ) ; } catch ( NumberFormatException ex ) { return false ; } if ( octet < 0 || octet > 255 ) { return false ; } start = pos + 1 ; octets ++ ; } return octets == 4 ; }
validate the given ipv4 address .
