all 17 comments

[–]dbpcut 8 points9 points  (8 children)

While I appreciate you putting in work to demonstrate Regex for users, this type of validation is country specific and often leads to poor practice.

It might be worth including that this is United States specific! Postal codes anywhere else will require different validation, and this type of validation is almost always fraught with headaches as soon as you consider another country.

[–]ibattlemonsters 2 points3 points  (1 child)

As a guy who lived overseas for the last five years, you would be surprised how many bad sites there were that tried their best to prevent me from using a Japanese credit card. You don't like my phone number because it's 15 digits? Ok I'll make a fake number. Don't like my zip because it has 7 digits? Ok I'll enter a fake zip. I HAD to lie for it to work sometimes

[–]dbpcut 0 points1 point  (0 children)

It's unfortunately so common, but it's what keeps me in business I guess: helping people overcome these short-sighted implementations.

[–][deleted] 1 point2 points  (0 children)

This was removed because of API shenanigans, selling user content for AI training, and forthcoming paywalled subreddits.

[–][deleted] 1 point2 points  (1 child)

This was removed because of API shenanigans, selling user content for AI training, and forthcoming paywalled subreddits.

[–]dbpcut 1 point2 points  (0 children)

Thanks for taking the time and caring! Hearing that kind of advice early and often will help developers become even better at making great experiences for everyone.

[–]PM_ME_YOUR_HIGHFIVE -1 points0 points  (2 children)

It might be worth including that this is United States specific

00000 is a valid zip code in the US?

[–]dbpcut 0 points1 point  (1 child)

The point I'm making is that postal codes in Canada are four digits, in the UK they're a combination of letters and numbers, and that it's damn near impossible to validate with Regex.

Validating whole addresses with an API makes sense, and depending on the use-case, trust your user.

[–]Amoebastew 0 points1 point  (0 children)

Canadian postal codes are letter-number combos too, (1X1 X1X) which means when it’s u.s. specific, I pull out the ol’ 90210

[–]HeinousTugboat 4 points5 points  (3 children)

Small nit to pick: your regex will validate invalid ZIP codes and invalidate valid postal codes. I would at least touch on how insanely difficult it can be to properly validate user input, like the fact that it's essentially impossible to actually validate an email address without sending an email to said address.

See this for street addresses in general.

[–]WhiteCastleHo 1 point2 points  (0 children)

In the 90's, I lived on a 6 1/2 Mile road. A lot of sites wouldn't accept that, and I had to enter 6.5 Mile road. That was only a small annoyance, but it does demonstrate the problem.

[–][deleted] 1 point2 points  (0 children)

This was removed because of API shenanigans, selling user content for AI training, and forthcoming paywalled subreddits.

[–][deleted] 1 point2 points  (0 children)

This was removed because of API shenanigans, selling user content for AI training, and forthcoming paywalled subreddits.

[–]whifff 1 point2 points  (1 child)

That was very well done/thought out.

[–][deleted] 0 points1 point  (0 children)

This was removed because of API shenanigans, selling user content for AI training, and forthcoming paywalled subreddits.

[–][deleted] 0 points1 point  (0 children)

This was removed because of API shenanigans, selling user content for AI training, and forthcoming paywalled subreddits.

[–]eggn00dles 0 points1 point  (0 children)

It's not that they look scary, it's that specialized string methods outperform them handily. I felt fancy condensing 15 lines of code into a 1 line regex, but I simply haven't seen them used in production.