Skip to content
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

validate integers min/max with regex? #94

Closed
emiltin opened this issue Dec 13, 2023 · 1 comment
Closed

validate integers min/max with regex? #94

emiltin opened this issue Dec 13, 2023 · 1 comment

Comments

@emiltin
Copy link
Contributor

emiltin commented Dec 13, 2023

Validating number ranges would be very easy if we send numbers as normal json numbers. Unfortunately we send them as strings.

That means we have to use regex if we want to validate them. Validating numbers with regex is ackward, but possible. For example, to validate that a number is in the range 0-255, you can use:

 ^([01][0-9][0-9]|2[0-4][0-9]|25[0-5])$

Ref:
https://www.regular-expressions.info/numericranges.html#:~:text=Searching%20for%20Numeric%20Ranges,%2D5%5D)%5Cb.

Handling leading zero or whitespace need a bit more.

Do we want to go down this route? Or wait for a core spec that sends numbers in native format?

@emiltin
Copy link
Contributor Author

emiltin commented Jan 3, 2025

Seems to complex, closing.

@emiltin emiltin closed this as completed Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant