user2636197 user2636197 - 1 year ago 74
iOS Question

Swift ios regex to only allow postive numbers 1 and up

I am trying to make a regex that only allows positive numbers starting from 1 and up

1 // pass
23 // pass
023 // fail
00234 // fail
2340 // pass

So far I have this
but this will only allow numbers starting with 0 which I dont want.

So how can I make a regex that only supports positive numbers/integers

Answer Source

What I mean is starting from 1 and up

Regex for a decimal number that doe not start in 0 is as follows:


Note that this regex will match sequences of digits that could not be represented as built-in numeric types in Swift.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download