public static void validateAddress ( String address ) { // Check for improperly formatted addresses Matcher matcher = ADDRESS_PATTERN . matcher ( address ) ; if ( ! matcher . matches ( ) ) { String message = "The address must have the format X.X.X.X" ; throw new IllegalArgumentException ( message ) ; } // Check for out of range address components for ( int i = 1 ; i <= 4 ; i ++ ) { int component = Integer . parseInt ( matcher . group ( i ) ) ; if ( component < 0 || component > 255 ) { String message = "All address components must be in the range [0, 255]" ; throw new IllegalArgumentException ( message ) ; } } }
Verifies that the given address is valid