How to prevent certain characters being input/saved in a field?

Hi,

I see we have the Validator that has the function for custom code.

If I wanted to prevent a user from inputting these characters, or stripping these characters (* or !)

What code would I required?

Hi Simmeon,

Pattern-matching validation can normally be achieved in the Data type settings.
But if you have a Data type that is shared across properties that need different validation, or you need more control over how you validate it, yes, you can use a Fragment Validator in Code Studio.

Once created, you select the Validator with the collapsed ‘Advanced’ panel of the fragment settings.

Example below of my attempt of what you are asking for, but you should review and test.

Paul

let current_value = fragment_presenter.get_value();
let valid_regex = /^[^*!]*$/;
if (! valid_regex.test(current_value)) {
return {
valid: false,
error: “Opps, you have a naughty * or ! in your input”
}
}
return true;

1 Like

@paul.frossell Thanks for the response. :+1: