unknown
unknown

Reputation: 55

How to validate decimal column in laravel

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?

Upvotes: 0

Views: 3776

Answers (2)

STA
STA

Reputation: 34838

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

Upvotes: 0

P. K. Tharindu
P. K. Tharindu

Reputation: 2730

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'

Upvotes: 2

Related Questions