0

The closest I found after trying all the various answers in earlier similar question was below:-

^[6-9]|[0-9]\d+$

but this still allows the leading zeros. Any help to restrict the leading zeros as well, please?

The answer suggested in How to match numbers between X and Y with regexp? is not my solution because it still allows numbers below 6.

dell
  • 171
  • 13
  • 2
    _“but this still allows the leading zeros”_ — Your second alternative states `[0-9]`; I wouldn’t expect otherwise. `[0-9]` means any digit from 0 to 9. You need the one from 1 to 9. – Sebastian Simon Oct 05 '20 at 00:44
  • Thanks,@user4642212! Your answer definitely a solution I've looked for the whole night last night! – dell Oct 05 '20 at 00:52
  • that one still allows numbers below 6, @ggorlen. – dell Oct 05 '20 at 00:56
  • I think you're taking the dupe target a bit too literally--it's not feasible for there to be a different post for how to write a regex to match every possible number or range. The way to go is to learn the general technique for matching numbers with regex from the canonical thread and apply it to your specific case. – ggorlen Oct 05 '20 at 01:35

1 Answers1

1

Try this one to avoid leading zero:

^(?:[6-9]|[1-9]\d+)$
Robo Robok
  • 21,132
  • 17
  • 68
  • 126
  • yep, this one is the precise answer, @Robo Robok! Because unlike my earlier amended regex, this one immediately punches not match pattern when I entered the negative values. Thanks a lot! – dell Oct 05 '20 at 01:07