question

JanineWhite-8464 avatar image
0 Votes"
JanineWhite-8464 asked BrianGonzalez-3377 answered

Determine if a string is numeric in Office Scripts

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-scripts-excel-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

BrianGonzalez-3377 avatar image
0 Votes"
BrianGonzalez-3377 answered

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?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.