-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v3.1.10
Feature type
New functionality
Proposed functionality
Regex validation for custom fields of JSON type with regex set in the "Validation" block of custom field settings.
When I try it now it says "Regular expression validation is supported only for text and URL fields".
Use case
Json fields are very nice to have, I've been converting to them all json data previously stored in Netbox as text strings for external systems and scripts to parse exactly as it was meant in #7452
I was hoping that with json type users will now be unable to put something non-json in such fields (this kills whatever is dependent on proper data format) but you can actually put anything in a json field as long as you frame it with quotes so it could be regarded as string and not checked for being a proper json.
A very simple regex demanding field's value to be framed with curly braces would be enough to counter this (yes, user can see an error message and put a single string inside of braces but at least this would require him to think twice drastically reducing mistakes).
Even better if I have very specific data in the field, let's say I use something like
{"numeric_parameter1": 123; "numeric_parameter2": 456, "codeword": "this"}
for racks, I could compose a regex allowing changing only values and according to my rules (i.e. [0-9]{1-4}, can't be negative, etc) providing superb data integrity with unseen ease of use.
Yes, I can solve this with extra custom validators but using a native already existing feature would be cool.
Database changes
No response
External dependencies
No response