Exercise: match a number

Write a function that given a string returns "true" if the string is a number and "false" if it is not a number. As there might be several definitions of what a number is, you need to create several solutions one for each definition:

  • Non negative integer.
  • Integer. (Will you also allow + in front of the number or only - ?
  • Real number. (Do you allow .3 ? What about 2. ?
  • In scientific notation. (something like this: 2.123e4 )

Tools

Solution