Please don't. Use regex to find something that looks like an IP then build a real parser. This is madness, its's extremely hard to read and a mistake is almost impossible to spot. Not to mention that it's slow.
Just parse [0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3} using regex (for v4) and then have some code check that all the octets are valid (and store the IP as a u32).
Fuck that, if for whatever reason I'm writing an IP validator by hand I'm disallowing leading zeros. Parsers are very inconsistent, some will parse 010 as 10, others as 0o10 == 8 (you can try that right now with a POSIX ping). Talk about a footgun.
Because 1.2.3.4 and 1.02.003.04 both map to the same number.
But 10.20.30.40 and 010.020.030.040 map to different numbers. It's often best to reject IPv4 addresses with leading zeroes to avoid the decimal vs. octal ambiguity.
True enough for database or dictionary storage, but a lot of times things get implemented in arrays where you still wind up with two copies of the same uint32.
That would allow for like, 2 trillion devices? Feels like a bandaid, my dude. Next you’re gonna suggest a giant ice cube in the ocean once a year to stop global warming.
You can use a ULA if you want to. That's essentially the IPv6 equivalent of a private IP.
Why though? Having the same IP for both internal and external solves a bunch of issues. For example, you don't need to use split horizon DNS any more (which is where a host name has a different IP on your internal network vs on the internet). You just need to ensure your firewalls are set up properly, which you should do anyways.
I thought it was pretty clear with me adding 13.37 that I was making a joke, the earlier post spoke about how just adding one octet would still be too few addresses, so I joked about adding one more octet.
Hurricanes cannot cross the equator. The equator is an imaginary line, and hence has zero mass. We can end every hurricane using zero point zero energy (0.0).
You could follow this logic and add 2 alphanumeric digits before 4 numeric octets. E.g. xf.192.168.1.1
This would at least keep it looking like an IP and not a Mac address. Another advantage would be graceful ipv4 handling with a reserved range starting with "ip" like ip.10.10.10.1
Oh yeah, great, let's change the fundamental protocol on which all the networks in the world are based. Now two third of the devices in the world crashed because you tried to ping 192.168.0.0.1
Holy hell yeah you did. How would you go about doing that in a single expression? A bunch of back references to figure out the country? What if that's not included? Oy.
You wouldn't. It's not possible. Which is what I told them.
And why would you want to? Legally if you change the given address, and it fails to get delivered - that is on you. Not them.
Some countries have addresses that are literally 'Last house on the left by the Big Tree. Bumban(Neighborhood). NN (Country)'. Any US Centric validation would fail this but I assure you - mail gets delivered just fine.
The only valid regex is (.+). Maybe add a separate country field (especially because some Americans wholeheartedly believe that the entire world should understand that "foobar, TX" means "foobar, Texas, United States") (don't get me started on states whose abbreviations are also ISO country codes).
Unfortunately I guess business people only care about getting fewer support calls for missing shipping details, not correctness or a couple of calls from customers who live in the boonies. Then the proper answer is a form with a bunch of fields... which Americans will inevitably fuck up by making the "State" field mandatory despite most countries not having an equivalent.
What I'd really do is use one of those services that automatically fill on the address using google maps or whatever. Not perfect, probably not free, but a whole lot less work for presumably way fewer PEBCAKs from customers.
If you're using one of those services then PLEASE allow manual entry / override because I've had forms like that which I were blocked from filing in because it didn't acknowledge that my address existed.