Laravel 的十进制验证规则

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22729773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:16:30  来源:igfitidea点击:

Laravel validation rules for decimal

validationlaravellaravel-4

提问by user3185936

Wondering if it's possible to set rules for validating decimal with the format XX,XX ? I have found that its possible with integer not decimal:

想知道是否可以设置验证十进制格式的规则 XX,XX ?我发现它可能是整数而不是小数:

public static $rules = array(
        'T_Badende_per_Time' => 'integer');

回答by Jason Lewis

You could always use the regexrule to validate it's of a given format:

您始终可以使用该regex规则来验证它的给定格式:

public static $rules = array(
    'T_Badende_per_Time' => 'regex:/[\d]{2},[\d]{2}/'
);

That will return true if you have 2 digits, followed by a comma, followed by another 2 digits.

如果您有 2 位数字,然后是逗号,然后是另外 2 位数字,则返回 true。