rsmp-nordic / rsmp_schema

JSON Schema for automatically validating RSMP messages
MIT License
1 stars 0 forks source link

validate integers min/max with regex? #94

Open emiltin opened 10 months ago

emiltin commented 10 months ago

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?