可能我缺少了一些东西,但是下面有模型
public class MyModel
{
public double WhateverButNotZero { get; set; }
}
是否有任何MVC内置的DataAnnotation来验证数字为“除零以外的所有内容”?
答案 0 :(得分:3)
localhost/laravel/public/my_page
答案 1 :(得分:2)
尝试使用regex annotation
public class MyModel
{
[RegularExpression("^(?!0*(\.0+)?$)(\d+|\d*\.\d+)$", ErrorMessage = "Not Equal to Zero")]
public double WhateverButNotZero { get; set; }
}
答案 2 :(得分:0)
您可以使用RegularExpression DataAnnotation属性。
[RegularExpression(@"^\d*[1-9]\d*$")]
public double WhateverButNotZero { get; set; }
希望What is the regex for “Any positive integer, excluding 0”有助于根据您的需要找出正则表达式。