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}$.
i need to have a regular expression which accept atleast 1 digit number and
Share
Uses a lookahead assertion to make sure there’s at least one nonzero digit. If there is one, then the rest of the expression only matches if there’s between 1 and 5 digits. Both conditions have to be met, or the expression won’t match.
Agreed, though, that if you’re trying to match a number, as opposed to a string of digits (like a ZIP code), it’d probably be better to compare numerically rather than with a regex.