Search⌘ K

DIY: Valid Number

Explore how to validate if a given string represents a valid decimal number. Learn to analyze numeric strings using characters such as digits, signs, decimal points, and exponents. This lesson helps you implement a function to return whether the input is a valid number, preparing you for similar coding interview questions.

Problem statement

Validate if a given string can be interpreted as a decimal number or not. Here is a list of characters that can appear in a valid decimal number:

  • Numbers - 0-9

  • Exponent - "e"

  • Positive/negative sign - "+"/"-" ...