Extracted IP address validator to a helper function.