Regex that matches integers only

前端 未结 10 569
执笔经年
执笔经年 2020-11-30 09:56

I\'m currently using the pattern: \\b\\d+\\b, testing it with these entries:

numb3r 
2
3454 
3.214
test

I only want it to catc

10条回答
  •  臣服心动
    2020-11-30 10:08

    This worked in my case where I needed positive and negative integers that should NOT include zero-starting numbers like 01258 but should of course include 0

    ^(-?[1-9]+\d*)$|^0$
    

    Example of valid values: "3", "-3", "0", "-555", "945465464654"

    Example of not valid values: "0.0", "1.0", "0.7", "690.7", "0.0001", "a", "", " ", ".", "-", "001", "00.2", "000.5", ".3", "3.", " -1", "+100", "--1", "-.1", "-0", "00099", "099"

提交回复
热议问题