How to add validators to custom fields

I’m creating a new custom field, using the related docs as a reference, and wanted to add a custom validator to the input. The docs only reference validators for the content builder settings, and not the custom field value itself.

I want to use a custom handler that parses the text and displays an error message, on save, if the input value is not valid (regex is not enough). Similar to what the JSON input does, where it shows “wrong JSON format”, when the input value is not valid JSON.

Can someone help?

Thank You!