Regular expression that would allow numbers from 1-9 excluding 0 and alphabets

96 Views Asked by At

I am looking for regular expression that would allow only positive integers(1-9)excluding 0 and alphabets. It can accept 01, 10 , 201 . It should not accept 0 , 00, 000.... I had tried most of the regular expressions available on google. But nothing worked. Pls help.

3

There are 3 best solutions below

6
On

0*(1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)*

0
On

Can be simplified like

0?[1-9][0-9]+

Check out http://regexpal.com it's online regex - can save a lot of time debugging

6
On

Try This:

[1-9][0-9]+

It will Exclude 0