Write an algorithm that will identify valid IPv4 addresses in dot-decimal format. IPs should be considered valid if they consist of four octets, with values between 0..255 (included).
hello >> not a possible ip
1.2.3 >> 3 octets
184.108.40.206.5 >> 5 octets
123.456.78.90 >> 456 is greater than 255
123.023.01.102 >> 023 and 01 are not valid
abc.def.sae.jei >> seriously?
222.-34.224.123 >> no negative numbers
Every language is welcome!
@Stoyan There are some issues with your otherwise good code:
- negative octets are possible
- leading zeroes are allowed in your implementation
Also, you could just output the method parameter instead of interpolating the octets together because the input obviously is valid at that stage.