-2

How can you check if the whole string is a number?

You can check if a string contains a number with regular expression. Can you use regular expressions as well to find out if a string is only a number, without any other characters?

"abc" is supposed to be false, it's not a number
"abc12" is supposed to be false, it's not a number
"123" is supposed to be true

0

1 Answer 1

0

if you are not using variables, and literal which is one quote, exactly what is in between the quotes.

'abc' -is [String]

'abc12' -is [String]

'123' -is [String]
Sign up to request clarification or add additional context in comments.

2 Comments

I am using variables. I don't want to check if something is a string. Your examples all give true, because they are all strings. I want to check if a string contains only digits.
You can change to variables on the left hand side, and on the right hand side change the [String] to [Int]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.