# Makie - Use of textbox validator

**URL:** <https://discourse.julialang.org/t/makie-use-of-textbox-validator/86487>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [August 29, 2022, 8:35am UTC](https://discourse.julialang.org/t/makie-use-of-textbox-validator/86487 "2022-08-29T08:35:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JB\_15](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jb_15/32/22992_2.png) [@JB\_15](https://discourse.julialang.org/u/JB_15)\
**Post date:** [August 29, 2022, 8:35am UTC](https://discourse.julialang.org/t/makie-use-of-textbox-validator/86487/1 "2022-08-29T08:35:40Z")

</div>

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

[https://makie.juliaplots.org/v0.17.13/examples/blocks/textbox/index.html](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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [August 29, 2022, 11:01am UTC](https://discourse.julialang.org/t/makie-use-of-textbox-validator/86487/2 "2022-08-29T11:01:51Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![JB\_15](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jb_15/32/22992_2.png) [@JB\_15](https://discourse.julialang.org/u/JB_15)\
**Post date:** [August 29, 2022, 12:27pm UTC](https://discourse.julialang.org/t/makie-use-of-textbox-validator/86487/3 "2022-08-29T12:27:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [August 29, 2022, 3:26pm UTC](https://discourse.julialang.org/t/makie-use-of-textbox-validator/86487/4 "2022-08-29T15:26:52Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![JB\_15](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jb_15/32/22992_2.png) [@JB\_15](https://discourse.julialang.org/u/JB_15)\
**Post date:** [August 29, 2022, 3:45pm UTC](https://discourse.julialang.org/t/makie-use-of-textbox-validator/86487/5 "2022-08-29T15:45:27Z")

</div>

It works ! Thanks
