gpt4 book ai didi

php - 如何在 Laravel5 请求类中验证 Money

转载 作者:IT王子 更新时间:2023-10-29 00:19:29 27 4
gpt4 key购买 nike

我的验证类是这样的

<?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'
);


}
}

我想将 recieved_amount 验证为 Money 字段就像如果输入了除金钱以外的任何东西,它应该被验证

谁能帮帮我

最佳答案

例如,您可以使用它(作为“金额”的金额):

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

正则表达式适用于“12”、“12.5”或“12.05”等数量。如果您想要多于两位的小数点,请将“2”替换为您需要的允许小数点。

关于php - 如何在 Laravel5 请求类中验证 Money,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33624710/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com