How to check money in a Laravel5 request class

My validation class is as follows

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class PaymentRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = array(

                       'invoiceid'=>'required',
                       'recieved_amount'=>'required',
                       'ref_no'=>'required',
                       'date'=>'required',
                       'comment'=>'required'
                       );


    }
}

I want to check recieved_amounthow the money field. As if nothing but money was entered, it must be confirmed

Can anyone help me on this

+4
source share
1 answer

You can use this, for example (being the "amount" of money):

public static $rules = array(
  'amount' => "required|regex:/^\d*(\.\d{1,2})?$/"
));

The regular expression will be used for numbers like '12' or '12 .5 'or '12 .05'. If you want more decimal points than two, replace "2" with the valid decimal places you need.

+19
source

Source: https://habr.com/ru/post/1615182/


All Articles