-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

1 Answers1

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]
Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
  • 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. – randomStack847 Mar 02 '21 at 14:56
  • You can change to variables on the left hand side, and on the right hand side change the `[String]` to `[Int]` – Shaqil Ismail Mar 02 '21 at 15:48