Search⌘ K
AI Features

DIY: Valid Number

Explore how to validate strings as decimal numbers in Ruby by checking the placement of digits, signs, decimal points, and exponents. This lesson helps you build a function that accurately determines if a given input string represents a valid number, preparing you for coding interview challenges.

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