Log in

View Full Version : PHP validation help



PinkFM
30-11-2011, 03:48 PM
Hi, basically I'm trying to get the PHP to check that $bookPrice (an input field) is either one or two numbers, a dot, then two numbers (13.99 or 3.99). At the moment it checks the correct amount of numbers, but works allows either a . to be entered or not (so it allows 1399).

Any help would be good :)
Thanks


if (preg_match("/^[0-9]{1,2}.[0-9]{2}/", $bookPrice) === 0) { $error[] = "The price did not contain a decmimal place.";}


oh forgot to add, it works if the price is only one number (3.99/399) but not if its (13.99/1399)

Dentafrice
02-12-2011, 05:36 PM
Here you go..

http://pastie.org/2955933

Want to hide these adverts? Register an account for free!