bazi
bazi

Reputation: 1876

Laravel validation : difference between numeric and integer?

in laravel docs there seems to be an integer and a numeric validation rule. i was wondering what the difference between the both was?

Upvotes: 31

Views: 25522

Answers (2)

Saumya Rastogi
Saumya Rastogi

Reputation: 13709

According to the Laravel's Source Code, both the validations have the following logic.

// For rule 'integer'
protected function validateInteger($attribute, $value)
{
    return filter_var($value, FILTER_VALIDATE_INT) !== false;
}

// For rule 'numeric'
protected function validateNumeric($attribute, $value)
{
    return is_numeric($value);
}

For more reference dig into the source code of Laravel - here >>

Upvotes: 8

Alexey Mezenin
Alexey Mezenin

Reputation: 163978

Integer is like a whole number without fraction: 2, 256, 2048.

http://php.net/manual/en/function.is-int.php

Numeric is any number including floating point numbers: 2.478, +0123.45e6

http://php.net/manual/en/function.is-numeric.php

Upvotes: 49

Related Questions