如何在Laravel5请求类中验证Money [英] How to validate Money in Laravel5 request class
本文介绍了如何在Laravel5请求类中验证Money的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的验证类如下
<?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
为货币"字段就像输入货币以外的其他内容一样,应该对其进行验证
I want to validate recieved_amount
as Money field Like if anything other than money is entered it should be validated
任何人都可以帮助我
推荐答案
您可以使用它(例如,金额"为金额):
You can use this, for example (being 'amount' the money quantity):
public static $rules = array(
'amount' => "required|regex:/^\d+(\.\d{1,2})?$/"
));
正则表达式将保留'12'或'12 .5'或'12 .05'之类的数量.如果您想要的小数点要多于2,请用所需的允许的小数代替"2".
The regex will hold for quantities like '12' or '12.5' or '12.05'. If you want more decimal points than two, replace the "2" with the allowed decimals you need.
这篇关于如何在Laravel5请求类中验证Money的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文