Laravel validate decimal 0-99.99

a 夏天 提交于 2019-11-30 08:19:16

The Laravel between validation rule is actually pretty powerful and can handle decimal values as well. So there's no need to use regex just do this:

'required|between:0,99.99'

The laravel(5?) between rule does always get it has to parse a decimal, you have to add numeric to it to validate correctly

'required|numeric|between:0,99.99',

this will work for number allowing two decimal precision:

function rules(){

   return [
   'field_name'=> array('regex:/^(?:d*.d{1,2}|d+)$/','min:1','max:10')
        ]; 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!