public boolean isValidInet4Address ( String inet4Address ) { // verify that address conforms to generic IPv4 format String [ ] groups = ipv4Validator . match ( inet4Address ) ; if ( groups == null ) { return false ; } // verify that address subgroups are legal for ( String ipSegment : groups ) { if ( ipSegment == null || ipSegment . length ( ) == 0 ) { return false ; } int iIpSegment = 0 ; try { iIpSegment = Integer . parseInt ( ipSegment ) ; } catch ( NumberFormatException e ) { return false ; } if ( iIpSegment > IPV4_MAX_OCTET_VALUE ) { return false ; } if ( ipSegment . length ( ) > 1 && ipSegment . startsWith ( "0" ) ) { return false ; } } return true ; }
Validates an IPv4 address . Returns true if valid .