title: How to allow only positive number to be entered in editorforfield in asp.net mvc 5
body: <p>I want a field to allow on positive number. I tried below attempt:</p>
  
  <p>Model</p>
  
  <pre><code>[Required]
  [GreaterThanZero(ErrorMessage = "Only positive number allowed.")]
  public int PositiveNumber { get; set; }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>  &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.PositiveNumber, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(m =&gt; m.PositiveNumber)
                  @Html.ValidationMessageFor(model =&gt; model.PositiveNumber, "*", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>Custom Validation</p>
  
  <pre><code>  public class GreaterThanZero : ValidationAttribute
      {
          public override bool IsValid(object value)
          {
              var x = (int)value;
              return x &gt; 0;
          }
      }
  </code></pre>
  
  <p>Question: Above solution works fine. I want to know is there any simple way to achieve it. By just using some inbuilt framework annotation/helpers or even <a href="https://foolproof.codeplex.com/" rel="noreferrer">FoolProof</a>?</p>
  
  <p>Kindly note that: using editorfor helped to allow only numbers (it is smart) but how about just the positive numbers.</p>