Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AbdulBazith's avatar

laravel validated with integer and entered integer, but not accepting ?

Guys iam working with a project in that, in store function in resource controller i given validation integer required

 'employee_phno'=>'required|integer',

and from form if i enter 9999999999(10 digits). mobile number is 10 digits.

if i give this its not accepting it showing the error

Errors:
The employee phno must be an integer.

why?

is there some other datatype to give mobile numbers which accepts 10 digits

0 likes
9 replies
Borisu's avatar

Well the integer rule does this

public function validateInteger($attribute, $value)
{
    return filter_var($value, FILTER_VALIDATE_INT) !== false;
}

If you try it yourself in the console you'll notice that both the string "9999999999" and the literal integer 9999999999 will return true. This means that they both pass validation. Having said that the simplest thing to do is just dd($request->all()) right before validation and inspect the fields.

You can also use the rule numeric. This is an even broader definition of your case.

And the last thing you might do is define your own validation rule, which will check if the value passed is a telephone number (has 10 integers in it etc.)

1 like
D9705996's avatar

@AbdulBazith - if your problem has been resolved can you please mark the best answer as the solution

1 like
devaxises's avatar

Try this 'employee_phno'=>'required|numeric',

1 like

Please or to participate in this conversation.