Jump to content

Need Help With Only Inserting Numbers In Textfield


iNko

Recommended Posts

Yesterday i got help with checking if textfield is empty, now i also need to make it so only numbers can be inserted in a specific textfield.

Heres the code that checks if field is empty:

if (empty($_POST['numbers'])) {
$error [] = 1;
} else {
$numbers= $_POST['numbers'];
}

 

Can i add another IF after the ELSE in this code that checks if its numbers?

  On 11/3/2012 at 8:42 AM, haku said:

I'm guessing you want something like this:

 

if (empty($_POST['numbers']))
{
$error [] = 1;
}
elseif(!is_numeric($_POST['numbers']))
{
$error[] = 2;
}
else
{
$numbers= $_POST['numbers'];
}

 

Thank you, this works very well.

Also as a side question, can i make this code without the 'elseif'? Something like this:

if ((empty($_POST['numbers'])) OR (!is_numeric($_POST['numbers']))
{
$error [] = 1;
}
else
{
$numbers= $_POST['numbers'];

 

also 'is_numeric' is for numbers, is there a name for 'is letters'?

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.