# Detecting the type of user input

**URL:** <https://discourse.julialang.org/t/detecting-the-type-of-user-input/122803>\
**Category:** New to Julia\
**Created:** [November 19, 2024, 6:43am UTC](https://discourse.julialang.org/t/detecting-the-type-of-user-input/122803 "2024-11-19T06:43:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [November 19, 2024, 6:43am UTC](https://discourse.julialang.org/t/detecting-the-type-of-user-input/122803/1 "2024-11-19T06:43:35Z")

</div>

Hello,  
How to identify the input type? For example, I want to get an input from the user with the `readline()` command. How can I tell if this input is a number or a string?

Thank you.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [November 19, 2024, 6:56am UTC](https://discourse.julialang.org/t/detecting-the-type-of-user-input/122803/2 "2024-11-19T06:56:44Z")

</div>

The input you will get, will _always_ be a string.  
You can test whether it is a number using `parse` , cf. [Numbers · The Julia Language](https://docs.julialang.org/en/v1/base/numbers/#Base.parse)  
or also the thread [Type-safe conversion of strings to numbers](https://discourse.julialang.org/t/type-safe-conversion-of-strings-to-numbers/105812)

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [November 19, 2024, 6:58am UTC](https://discourse.julialang.org/t/detecting-the-type-of-user-input/122803/3 "2024-11-19T06:58:18Z")

</div>

You should use [`tryparse`](https://docs.julialang.org/en/v1/base/numbers/#Base.tryparse) if you intend to check if it is what you want, not `parse` which will raise an exception.

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [November 19, 2024, 7:16am UTC](https://discourse.julialang.org/t/detecting-the-type-of-user-input/122803/4 "2024-11-19T07:16:07Z")

</div>

Hi,  
Thank you so much.  
I wrote a code like below:

```julia
print("Please enter something: ")
a = readline()
if ((tryparse(Int, a) == nothing))
    println("You have entered a string")
else
    println("You have entered a number")
end

```
