JSON numbers Regular Expression

后端 未结 3 1455
长发绾君心
长发绾君心 2021-02-14 04:59

I\'m trying to write a regular expression for strings that are numbers in JSON. I\'m still new to writing Regular expressions, I found a diagram of a machine for JSON numbers h

3条回答
  •  猫巷女王i
    2021-02-14 05:37

    acheong87's answer should provide the regex that you require. However, if you are just trying to check if a string returned via JSON "is a number" then you can do this:

    var valueAsString = "55e-2";
    var isANumber = !isNaN(valueAsString);
    

提交回复
热议问题