How to Validate Money in Laravel request class?
Hi dev,
In this blog,I will explain how to validate money in laravel request class.i can laravel money validation using regex.you can using regex format to Money validation in laravel we will easy following example to show laravel in money validation.
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.so I will add 'amount'=>"required|regex:/^\d+(\.\d{1,2})?$/" or 'amount'=>"required|regex:/^\d{1,13}(\.\d{1,4})?$/" this line in my rules array , ANd will it work for both integer and float.
Laravel Money Validate Example
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function store(Request $request){
$request->validate([
"product" =>" required",
"amount" =>" required|regex:/^\d+(\.\d{1,2})?$/",
]);
return redirect()->back();
}
or
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function store(Request $request){
$request->validate([
"product" =>" required",
"amount" =>" required|regex:/^\d{1,13}(\.\d{1,4})?$/",
]);
return redirect()->back();
}
it will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial