Hard · Strings

Valid Number

Given a string s, return true if it is a valid number — an optionally signed integer or decimal (such as "7", "7.", ".5" or "-3.25"), optionally followed by 'e' or 'E' and an optionally signed integer — and false otherwise; no spaces or other characters are allowed.

Examples

Example 1

{
  "s": "2e-3"
}

Output: true

Example 2

{
  "s": "1a"
}

Output: false

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Strings problems