# Struct field name validate

**URL:** <https://discourse.julialang.org/t/struct-field-name-validate/64499>\
**Category:** General Usage\
**Tags:** struct\
**Created:** [July 12, 2021, 11:03am UTC](https://discourse.julialang.org/t/struct-field-name-validate/64499 "2021-07-12T11:03:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [July 12, 2021, 11:03am UTC](https://discourse.julialang.org/t/struct-field-name-validate/64499/1 "2021-07-12T11:03:43Z")

</div>

Hellow!

I am looking for a reliable method to validate structure field names. Structure code is generated based on user input.

I think about eval(), but…

```julia
x = :else
exp = :($x = "Oops!"; print($x))
eval(exp) # -> Oops!

```

then i tried using Base.isidentifier(), but

```julia
Base.isidentifier(:else) # -> thue

```

this is not what i need.

If i will checking against a list of registered names, i will need a supporting this list.

May be…

```julia
try
    include("generated_field_name_test.jl")
catch e
    # ...
end

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 12, 2021, 11:35am UTC](https://discourse.julialang.org/t/struct-field-name-validate/64499/2 "2021-07-12T11:35:00Z")

</div>

```julia
julia> struct A     
         field_a    
       end          
                    
julia> fieldnames(A)
(:field_a,)         

```

Though I’d recommend checking the field names _before_ creating the struct.

---

<div class="post-metadata">

**Author:** ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)\
**Post date:** [July 12, 2021, 12:35pm UTC](https://discourse.julialang.org/t/struct-field-name-validate/64499/3 "2021-07-12T12:35:57Z")

</div>

There is also the function `hasfield`, although I’m not entirely confident from your example code that that’s what you’re looking for: `hasfield(Complex{Float64}, :re)`.
