What's the best way to validate numbers with comma as decimal separator?

前端 未结 2 689
不思量自难忘°
不思量自难忘° 2021-01-18 22:45

In a Laravel app, I have a form on which I need to validate numbers with a comma as the decimal separator. For the moment, it only works with a point because my validation r

2条回答
  •  萌比男神i
    2021-01-18 23:05

    Laravel supports regex pattern in validation rule so you can use the given pattern to match something like 12,365.00 and it's recommended to use an array instead of pipe when using regular expressions as a rule

    $rules = array('amount' => array('match:/^[0-9]{1,3}(,[0-9]{3})*\.[0-9]+$/'));
    

    Check this link. Also, if you want to remove the commas for any reason then check this answer.

提交回复
热议问题