1

I am trying the following RegEx to validate the decimal value like

 [RegularExpression("^(?:\\d{1,100000000}(?:\\.\\d{0,6})?)?$")]
        [Range(double.MinValue,double.MaxValue)]
        public decimal Amount { get; set; }

rendering in the view like

    <div class="editor-field">
       <%:Html.TextBoxFor(x=>x.Amount)%>       
       <%:Html.ValidationMessageFor(x=>x.Amount) %>
    </div>

the problem is it puts a 0 in the textbox by default, please guide me find out the problem, also if there is a better way to validate the decimal field please do mention...

John x
  • 4,031
  • 8
  • 42
  • 67
  • check this post http://stackoverflow.com/questions/7375729/mvc3-3-decimal-places-on-type-double-with-leading-zero – Amir Ismail Jun 11 '12 at 12:54

1 Answers1

2

Try settings the type of your Amount property to nullable:

public decimal? Amount { get; set; }
Fabio Milheiro
  • 8,100
  • 17
  • 57
  • 96