Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 5 Data Annotation "Not Equal to Zero"

Probably I am missing something, but having the model below

 public class MyModel
 {
     public double WhateverButNotZero { get; set; }
 }

is there any MVC built-in DataAnnotation to validate the number as "everything but zero"?

like image 458
znn Avatar asked Sep 07 '25 01:09

znn


1 Answers

Regex to the rescue:

public class MyModel
{
    [RegularExpression("(.*[1-9].*)|(.*[.].*[1-9].*)")]
    public double WhateverButNotZero { get; set; }
}
like image 143
SBFrancies Avatar answered Sep 09 '25 14:09

SBFrancies