DEVILofDARKNESS Posted August 12, 2009 Share Posted August 12, 2009 It's the first time I used regex, so before I launch it on the WWW, I want to know if it's well formed and safe. (It's an easy one, to check if the ammount of a textbox is a value above 0) preg_match("/^[^-]?[1-9]+/", $_POST['ammount'], $matches) Quote Link to comment Share on other sites More sharing options...
thebadbad Posted August 12, 2009 Share Posted August 12, 2009 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)) Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted August 12, 2009 Author Share Posted August 12, 2009 Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.