Jump to content

First time regex, is this right?


DEVILofDARKNESS

Recommended Posts

Your pattern currently tries to match an optional character NOT a hyphen (at the very start of the string) followed by 1 or more digits being 1 to 9 (e.g. 110 wouldn't match). And anything could follow after that (so you would want to use a dollar sign that matches at the end of the string). If you strictly want to check for an integer above 0, you can use

 

~^[1-9][0-9]*$~D

 

But in that case you could obviously simply use built in functions:

 

if (ctype_digit($_POST['ammount']) && ((int) $_POST['ammount'] > 0))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.