Makie - Use of textbox validator

Hi
I’m trying to use the validator from the Makie Textbox

https://makie.juliaplots.org/v0.17.13/examples/blocks/textbox/index.html

Could anybody give me an example of how to use the validator?
My goal is to verify that all the comma separated values are numbers… “a, 2, 3, 4, 5, 6”

Regards
JB

From those docs:

[The validator] can be a Regex that needs to match the complete string, or a Function taking a String as input and returning a Bool

So you can either use a regex like r"\d+(, \d+)*" or something to that effect, or you use a function that returns true only if your requirement is met, and that could be:

function validator_func(str)
    parts = strip.(split(str, ","))
    all(parts) do part
        tryparse(Int, part) !== nothing
    end
end

Many thanks

In fact I don’t know how to call the validator function on the Textbutton, i.e, how to call the function properly (do I have to use the validator argument ?). Sorry for the basic question, I’m starting with Julia.

Should I use

tb = Textbox(f[1, 1], placeholder = “Enter a string…”, validator = validator_func())
or
tb = Textbox(f[1, 1], placeholder = “Enter a string…”, validator = validator_func(string, validator))
or

using GLMakie
function validator_func(str)
parts = strip.(split(str, “,”))
all(parts) do part
tryparse(Int, part) !== nothing
end
end
f = Figure()
tb = Textbox(f[1, 1], placeholder = “Enter a string…”, validator = validator_func(string))
f

You pass the function itself, so that the Textbox can call it itself when it wants to check if the text is valid. So in this case simply validator = validator_func

It works ! Thanks