8000 [feat] `z.number().latitude()` and `z.number().longitude()` · Issue #2600 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[feat] z.number().latitude() and z.number().longitude() #2600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hudson-bruno opened this issue Jul 21, 2023 · 5 comments
Open

[feat] z.number().latitude() and z.number().longitude() #2600

hudson-bruno opened this issue Jul 21, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@hudson-bruno
Copy link

Latitude and longitude are used in a variety of applications, it feels like this simple validation is missing, currently is possible to validate chaining min and max but it would be better if this validation was abstracted away.

const latitude = z.number().min(-90).max(90)
const longitude = z.number().min(-180).max(180)

// Proposed
const latitude = z.number().latitude()
const longitude = z.number().longitude()
@csulit
Copy link
csulit commented Apr 28, 2024

I hope this gets shipped soon.

@l2aelba
Copy link
l2aelba commented Jan 16, 2025

For me using Regex is much better
Example:

{
  latitude: z.string().regex(/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/).optional()
  longitude: z.string().regex(/^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$/).optional()
}

Ref: https://stackoverflow.com/a/31408260/622813

@farazalidev
Copy link

This is really needed in zod, a must property

@ronnyandre
Copy link

+1

1 similar comment
@jmoralesfu
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants
0