Reg-ex to validate a sting with digits only but all Zeros are not allowed [closed]

Code

See regex in use here

^(?!0+$)\d{1,5}$

Results

Results as described by the header for the section.

** VALID **
1
12345
00001
01
10

** INVALID **
0
00000
123456

Explanation

  • ^ Assert position at the start of the line
  • (?!0+$) Negative lookahead ensuring what follows is not 0 one or more times, followed by the end of the line
  • \d{1,5} Any digit between 1 and 5 times
  • $ Assert position at the end of the line

Browse More Popular Posts

Leave a Comment