regex 1-9999 for form validation

前端 未结 4 1275

I am trying to write some form validation, I need one of the inputs to be 1-9999. I know nothing about regular expressions ( never used them before) and here is my first attempt

4条回答
  •  醉酒成梦
    2021-01-21 16:02

    This Regex should not match numbers that start with 0 a part from 0

    Regex: /^(?!(0\d))\d{1,4}$/

    Regex (Exclude Zero): /^(?!(0))\d{1,4}$/

    Test: https://regex101.com/r/zfCKel/2

提交回复
热议问题