public static boolean isValidIPV4Address ( String value ) { int periods = 0 ; int i = 0 ; int length = value . length ( ) ; if ( length > 15 ) return false ; char c = 0 ; String word = "" ; for ( i = 0 ; i < length ; i ++ ) { c = value . charAt ( i ) ; if ( c == ' ' ) { periods ++ ; if ( periods > 3 ) return false ; if ( word == "" ) return false ; if ( Integer . parseInt ( word ) > 255 ) return false ; word = "" ; } else if ( ! ( Character . isDigit ( c ) ) ) return false ; else { if ( word . length ( ) > 2 ) return false ; word += c ; } } if ( word == "" || Integer . parseInt ( word ) > 255 ) return false ; if ( periods != 3 ) return false ; return true ; }
Takes a string and parses it to see if it is a valid IPV4 address .