title: How to make entry field to allow numbers only using EF and Data Annotations?
body: <p>I am trying to figure out if there is a way to make sure that numeric only input is allowed using Data Annotations and Entity Framework.</p>
  
  <p>I am using the following code</p>
  
  <pre><code>[Required]
  [DisplayName("Client No")]
  [Column("client_no", TypeName = "smallint")]
  public virtual Int16 Number { get; set; }
  </code></pre>
  
  <p>I want this to be displayed using number class. </p>
  
  <p>In one place I use the following</p>
  
  <pre><code>&lt;input type="number" name="searchClientNo" class="numericOnly" /&gt;&lt;br /&gt;
  </code></pre>
  
  <p>but in the entry form I am using</p>
  
  <pre><code>@Html.EditorFor(m =&gt; m.Number, EditorTemplate.TextBox)
  </code></pre>
  
  <p>where I have a custom made EditorFor with the following code</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
      @Html.Label((ViewData.ModelMetadata.DisplayName??ViewData.ModelMetadata.PropertyName),
          new Dictionary&lt;string, object&gt;
              {
                  { "for", ViewData.ModelMetadata.PropertyName }
              })
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.TextBox("", (object)Model,
          new Dictionary&lt;string, object&gt;
              {
                  { "id", ViewData.ModelMetadata.PropertyName },
                  { "name", ViewData.ModelMetadata.PropertyName },
                  { "class", "text-box single-line"},
                  { "data-bind", "value: " + ViewData.ModelMetadata.PropertyName },
              })
      @Html.ValidationMessage(ViewData.ModelMetadata.PropertyName,
          new Dictionary&lt;string, object&gt;
              {
                  { "data-valmsg-for", ViewData.ModelMetadata.PropertyName }
              })
  &lt;/div&gt;
  </code></pre>
  
  <p>I am wondering how can I keep this code without changes but still use the numeric only textbox. Do I need to use UIHint?</p>
  
  <p>Or alternatively, is it possible to make my existing EditorFor smarter?</p>
  
  <p>I found this blog post <a href="http://robseder.wordpress.com/2012/06/01/uihint-displaytemplates-and-editortemplates-in-mvc/" rel="noreferrer">http://robseder.wordpress.com/2012/06/01/uihint-displaytemplates-and-editortemplates-in-mvc/</a> but I am already using a custom EditorFor. May be I need to add a new type, say, EditorTemplate.NumericTextBox and add another editor? This sounds like it may work, I am going to try this tomorrow...</p>
  
  <p>Thanks a lot in advance.</p>