Determine if a string is numeric in Office Scripts

Janine White 1 Reputation point
2022-04-18T20:59:42.85+00:00

How do I determine if a string is numeric in Office Scripts if the string cannot have any letters in it? For example, 'a1234' should not be a number. The Number methods like parsefloat, parseInt, IsInteger, and isNan don't help because they accept strings that have any numbers in them when wrapped in Number (Number(value) or +value) or don't accept strings.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,653 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Brian Gonzalez 76 Reputation points
    2022-04-20T17:12:19.357+00:00

    I show that when the string 'a1234' is passed into Number.IsInteger(), the value is false:

    function main(workbook: ExcelScript.Workbook){
      let str: string = "a1234"
      console.log(Number.isInteger(str)) //false
    }
    

    Is this what you were expecting? If not, what were you expecting? Or what are you trying to achieve?

    0 comments No comments