+ 29
IP Validation Challenge 2⃣5⃣5⃣.2⃣5⃣5⃣.2⃣5⃣5⃣.0⃣
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). valid input: 1.2.3.4 123.45.0.86 0.0.0.0 255.255.255.255 invalid input: hello >> not a possible ip 1.2.3 >> 3 octets 1.2.3.4.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!
41 Answers
+ 22
+ 16
Marking thread. Will come back to this later.
+ 16
+ 14
@Andrea : Edited the code accordingly!
+ 12
+ 8
https://code.sololearn.com/ci0L14KWyu3d/?ref=app
+ 7
I'm a bit busy today, so this one is kind of crude.
https://code.sololearn.com/cIU09T5S33Cp/?ref=app
+ 4
@Teja 012 is not valid so 4 example
123.123.012.123 is not a valid ip
Edit: good work!
+ 4
https://code.sololearn.com/cPpz06Q8S3B0/?ref=app
+ 4
here's my link
Thx python regex lol
https://code.sololearn.com/c9u7OYp4uL88/#py
+ 4
My solution with Python:
https://code.sololearn.com/cRRD2bOZkiSX/?ref=app
+ 4
@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.
+ 4
Special approach:
Filter using language features and behaviors, not by values
Primarily by: exception, -mod behavior, recast length
https://code.sololearn.com/cd03CF9McF30/?ref=app
+ 3
@calvin this is cheating! ahahah!
+ 3
@amr 123.012.123.123 is not valid because 012 is not valid
Edit: nice!
+ 3
fixed
+ 3
did I? which one?