Jump to content

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?

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'?

Edited by iNko
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.