Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expression for 5 digit number excluding '00000'

i need to have a regular expression which accept atleast 1 digit number and maximum 5 digit number and if user enter zero in the following fashion like '00','000','0000','00000' then expression should reject such inputs. currently, i am using ^[0-9]{1,5}$.

like image 733
ravi Avatar asked Jan 21 '26 11:01

ravi


1 Answers

If you'd make sure that the user's input is formatted as a 5 digit number with leading zeroes, then the following regex would work:

^[0-9]{5}(?<!00000)$

This uses negative lookbehind to ensure that the string entered was not 5 zeroes.

like image 66
Hiery Nomus Avatar answered Jan 23 '26 01:01

Hiery Nomus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!