Search⌘ K

DIY: Valid Number

Understand how to validate if a string represents a valid decimal number by analyzing characters like digits, exponents, signs, and decimal points. This lesson helps develop problem-solving skills to implement a function that checks numeric validity, a common coding interview task.

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 - "+"/"-" ...