Validate fields in Lavavel 9 compliant with mysql field type decimal(8,2)
1. Verify the fields that conform to the MySQL field type Decimal(8,2) in Lavavel 9. as shown in Figure 1
`return_package_length` decimal(8,2) NOT NULL DEFAULT '0.00' COMMENT '退货包裹长度(厘米)'
2. The final realization is as follows
$validator = Validator::make(
$params,
[
'return_package_length' => [
'numeric',
'min:0.00',
'max:999999.99',
'regex:/^\d{0,6}(\.\d{1,2})?$/'
],
],
[
]
);
if ($validator->stopOnFirstFailure()->fails()) {
throw new BusinessException(BusinessException::MODULE_ORDER, $validator->getMessageBag()->first());
}
3. Try respectively: -4 (fail), 0 (success), 5 (success), 999999.99 (success), 999999.990 (success), 999999 .991 (failed), 9999990.99 (fail), 0.09 (success), 0.009 (fail), 0.0000001 (failed), in line with expectations. as shown in Figure 2

