Skip to content

[Validator] feature coordinates validator #61313

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
wants to merge 5 commits into
base: 7.4
Choose a base branch
from

Conversation

zairigimad
Copy link
Contributor

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues #61312
License MIT

@zairigimad zairigimad force-pushed the feat/coordinates-validator branch from 7b62e33 to 09fed9d Compare August 3, 2025 17:24
@MatTheCat
Copy link
Contributor

MatTheCat commented Aug 3, 2025

It seems weird to validate a numeric input using a regex. Functionally those constraints are Range so I’m not sure they’re needed. If they are, it probably would make more sense for them to be validated by the RangeValidator.

@zairigimad
Copy link
Contributor Author

It seems weird to validate a numeric input using a regex. Functionally those constraints are Range so I’m not sure they’re needed. If they are, it probably would make more sense for them to be validated by the RangeValidator.

You're right that using Range makes sense for numeric validation — and we can use it to enforce geographic bounds. However, here’s why we combine it with a regex.
Range assumes you're working with actual floats or integers. It doesn't validate the format of input values like "+45.0", "0045.00", or "45,0" — all of which can be valid geographic coordinates but might be misinterpreted or bypass format expectations. Regex ensures proper structure (e.g. optional sign, correct decimal form), while Range enforces the numeric limits. So the two constraints are complementary.

@MatTheCat
Copy link
Contributor

Range assumes you're working with actual floats or integers

It also supports numeric strings, so it seems that it would solve all your use-cases?

@alexandre-daubois
Copy link
Member

alexandre-daubois commented Aug 4, 2025

I don't know if I'm in favor of this. I get the usage, but should we add new constraints every time we have a new format to validate without further validation besides a regex matching? This could be done with Assert\Regex() and a well named constant to hold the regex, isn't it?

Also on a side note: translations are added to the lowest maintained branch to ease maintainers work (and avoid conflicting IDs on upmerge). So if this one gets merged, it should be done in a separate PR.

@zairigimad
Copy link
Contributor Author

I don't know if I'm in favor of this. I get the usage, but should we add new constraints every time we have a new format to validate without further validation besides a regex matching? This could be done with Assert\Regex() and a well named constant to hold the regex, isn't it?

Also on a side note: translations are added to the lowest maintained branch to ease maintainers work (and avoid conflicting IDs on upmerge). So if this one gets merged, it should be done in a separate PR.

true the Regex handle it, but we need to use the same regex everywhere in the code.i did this proposal to avoid duplication and for a better DX , readability ...

@MatTheCat
Copy link
Contributor

I still don’t understand why we’d want to validate a numeric input using a regex?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy