FastPrepRestricted Decimal Number Validator
Problems/Restricted Decimal Number Validator

Restricted Decimal Number Validator

LinkedIn logoLinkedIn● EasyNEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report supplied the callable signature, six classifications, and the optional-sign/single-decimal rule. Empty-input, whitespace, plus-sign, leading-zero, and size behavior were fixed for deterministic practice. The judged core task matches the visible source at about 94%.

You are given a string toTest. Return true exactly when it represents a number in the restricted decimal grammar below.

  • An optional minus sign - may appear only as the first character.
  • At least one ASCII digit must follow the optional sign.
  • An optional decimal point . may appear at most once, and it must have at least one digit on each side.
  • No other characters, whitespace, exponent notation, or leading plus sign are accepted.

Leading zeros are allowed.

Function

isNumber(toTest: String) → boolean

Examples

Example 1

toTest = "234"return = true

Every character is an ASCII digit.

Example 2

toTest = "-455"return = true

A single leading minus sign is allowed.

Example 3

toTest = "1e2"return = false

Exponent notation is outside the accepted decimal grammar.

Example 4

toTest = "12^2"return = false

The caret is not a digit or the optional decimal point.

Example 5

toTest = "23.23"return = true

There are digits on both sides of the only decimal point.

Example 6

toTest = "2.2.4"return = false

A valid representation may contain at most one decimal point.

Constraints

  • 0 ≤ toTest.length ≤ 100000
  • toTest consists of printable ASCII characters.

More LinkedIn problems

  • Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
  • Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
  • Sum an Arbitrary-Dimensional ArrayPHONE SCREEN · Seen Oct 2026
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public boolean isNumber(String toTest) {
        // write your code here
    }
}
Checking account…