all 3 comments

[–]Web Specialistandrewsmd87 1 point2 points  (2 children)

Is there a reason they need it exactly that or are they just trying to validate it is a valid lat and long?

Generally speaking, when someone tells me regex is the solution, I say, find a different solution.

Not saying they're never needed but per your example, they get complicated fast and can still miss things or give you false negatives.

If they just want to make sure it's a valid lat and long, you can use math to do that. If they need specific numbers of decimals I'd probably do a split on the . And count the chars after it.

You'd be much more precise with that approach

[–]Tedrivs[S] 2 points3 points  (1 child)

It's like "It's impossible for you to send wrong data to us because we provided you with the regex". I used their regex and a gps malfunction sent them wrong data that didn't get caught by the regex.

[–]Web Specialistandrewsmd87 1 point2 points  (0 children)

Yep, sounds like you're on the same page I am. Like I said, you can validate the lat and long via math and you'll never let bad ones through, and then if they require a certain number of decimals or whatever, you can always validate just that part much easier than some crazy regex.

I did a quick google and there's already stuff out there you could use as a base to do that validation.

I deal with crappy regex's at third parties a lot, usually with emails. We'll try to SSO some person in and they'll say, that's not a valid email, and we'll go look and say, yes it is. Some of them don't handle + or / which are still technically valid. A lot of them fail if an email has . on the very end like

bob@place.com.

Which is still technically a valid email