Help Help - 1 year ago 63
PHP Question

Regular Expression (PHP) => greater that or if not

It is possible to have in a regular expression (php), something like '>' or 'if not' ¿?

For example: I have a 5 number string 'XXXXX': '00054', '47690', '20593'...

I need a regular expression that verify:

  1. 5 numbers

  2. Greater that 1

I had this: '/^[0-9]{5}$/' but doesn't verify the greater than '00001' !

I'm looking for something like '>' or 'if not 00000'...


PS: I know that can be done with: if((int)$string > 1)

Answer Source

I can figure out 2 ways:


This first checks that the start is not followed by 5 zeros, then searches for 5 digits.


This one checks for 5 combinations, each of which contains a non-zero digit in one of the 5 positions.

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