Back to problems

Validate an IPv4 address string

Algorithm · Figma · Medium

A string s is considered a valid IPv4 address when it matches the form x1.x2.x3.x4 and each component x1 through x4 satisfies all of the following: s may contain only decimal digit characters and the . character; any other character makes it invalid. Splitting s on the . character must yield exactly four non-empty components. Each component must be a decimal integer in the inclusive range $$[0,255]$$. No component may have a leading zero unless the component is exactly "0";…

Checking your access…