Validate IP Address

Advanced

Description

In this fun Python coding challenge, you'll write a function to validate IP addresses! An IP address is a string of numbers separated by periods, and each number in the string (called an "octet") must be within the range of 0 to 255.

Your task is to write a function validate_ip_address(ip_address: str) -> bool that takes a string ip_address and returns True if it's a valid IPv4 address, and False otherwise.

A valid IP address must meet the following criteria:

  • It consists of exactly 4 octets.
  • Each octet must be a number between 0 and 255.
  • Numbers cannot be prefixed with zeros unless they are zero (e.g., "01", "001" are not allowed).

Examples

validate_ip_address("192.168.0.1") # returns True validate_ip_address("255.255.255.255") # returns True validate_ip_address("192.168.0") # returns False (only 3 octets) validate_ip_address("256.100.50.25") # returns False (256 is out of range) validate_ip_address("192.168.01.1") # returns False (01 is not allowed)

Let's get started by implementing the function! Happy coding!

Geek
Inputs

Arg 1:

"192.168.0.1"
Expected Output
true
Actual Output