Log in

View Full Version : Validate int



d-machine
08-26-2009, 10:34 AM
Hi,

I have a simple form with a text field

and I want to check if it was written there a integer.

I used is_numeric($_POST["input"]) but it accepts also double number.

What can I do?

prasanthmj
08-26-2009, 11:21 AM
use regular expression matching.

if(!preg_match("/^[\-\+]?[\d]*$/",$_POST["input"]))
{
//error
}


The following pages might be helpful:
PHP Form Validation Script (http://www.html-form-guide.com/php-form/php-form-validation.html)
and
JavaScript Form Validation (http://www.javascript-coder.com/html-form/javascript-form-validation.phtml)