Support the ongoing development of Laravel.io →
Requests Input
Last updated 1 year ago.
0
Solution

Input values will always be strings. is_int() will fail because of that, regardless if the string value is in integer-format.

I'd advise you utilize Laravel's Validation library to help with this, because you're basically reinventing that wheel.

Last updated 1 year ago.
0

It turns out, you could do some of these.

$a = '10293';

var_dump(is_int($a)); // false
var_dump(is_numeric($a)); // true
var_dump(preg_match('/\d/', $a) === 1); // true

$b = 'foo';
var_dump(is_int($b)); // false
var_dump(is_numeric($b)); // false
var_dump(preg_match('/\d/', $b) === 1); // false


$c = 10293;
var_dump(is_int($c)); // true
var_dump(is_numeric($c)); // true
var_dump(preg_match('/\d/', $c) === 1); // true

PS: if you just want to make sure the number is a non-zero "number", you could do the following, or you could do as @cryode said, using the Validation Class. :D

if(intval(Input::get('skin')) > 0) { 
   ... 
}
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Joe96 joe96 Joined 28 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.