0

I have a column month_1 in table who have type is decimal(12,2)

how can i validate it in my Request class?

public function rules()
    {
        return [
            'month_1' =>'required',
         ];
    }

do i have to write between:0,99.99 ? will it be applicable to my case also?

unknown
  • 45
  • 2
  • 8
  • **12.2** or **12,2**? _12,2_ is not a decimal value – STA Sep 30 '20 at 05:40
  • @sta in migration " $table->decimal('month_1',12,2)->nullable();" – unknown Sep 30 '20 at 05:41
  • Does this answer your question? [Laravel validate decimal 0-99.99](https://stackoverflow.com/questions/29734046/laravel-validate-decimal-0-99-99) – Jignesh Joisar Sep 30 '20 at 05:43
  • @JigneshJoisar please check updated question – unknown Sep 30 '20 at 05:47
  • `'month_1' =>'required|between:12,12.30',` – STA Sep 30 '20 at 05:47
  • @sta if its correct then please post it in answer – unknown Sep 30 '20 at 05:50
  • 1
    Let me explain, **12,2** means : **decimal(p,s)/decimal(12,2)** is a number that has **10/(p-s)** digits before the decimal and **2/s** digit after the decimal. Example : _1111111111.11_ – STA Sep 30 '20 at 05:55
  • I think you want to store **month number,date**? Then it will be **4.2** example : 12.30 or 1.01 – STA Sep 30 '20 at 05:59
  • Do you want to validate that any decimal number passed is at most two decimal digits or just that it fits in your database column since the digits after the first two would probably just be ignored – apokryfos Sep 30 '20 at 06:57

2 Answers2

2

decimal('month_1', 12, 2) means total of 12 digits including 2 decimal digits.

So it should be something like:

'required|numeric|between:0,9999999999.99'
P. K. Tharindu
  • 2,565
  • 3
  • 17
  • 34
0

I think you want to store month number,date? Then it will be 4.2

That mean that the database type is decimal(4, 2), then this means that your column is set up to store 4 places (scale), with 2 to the right of the decimal (precision). You should treat this as a decimal CLR type. Example : 12.31, 12.01, 123.4 but not 1234.567 or 12345.67.

You can validate like this :

'month_1' =>'required|between:12.01,12.31',

This will validate number only, between 12.01 to 12.31

STA
  • 30,729
  • 8
  • 45
  • 59