0

Hi I have the following textbox

@Html.TextBoxFor(r => model.Hours, new { @class = "form-control NumberVal input-sm text-right", @data_cp_min_value = 0, @data_cp_max_value = 10000, @Value = String.Format("{0:#,##0}", model.Hours) })

howevery my js validation returns true when i do IsNaN(input.val())

Also when submitting the form the decimal part is lost as the Value is being submitted.

How can i solve this?

den
  • 709
  • 2
  • 7
  • 19

2 Answers2

0
<script type="text/javascript">
function onRegisterNumberChange(value)
{
 if(value=="")
   return false;

}
</script>

@Html.TextBoxFor(r => model.Hours, new { @class = "form-control NumberVal input-sm text-right", @data_cp_min_value = 0,@onclick = "onRegisterNumberChange(this.value);", @data_cp_max_value = 10000, @Value = String.Format("{0:#,##0}", model.Hours) })
0

can you provide your js code?

or if you want, you can use another solution by using the RangeAttribute to achieve what you want

example in your model just put the following

[Range(0,1000,"value should be between [0,1000]!")]
public int Hours{get;set;}

and you can use the idea mentioned here Using Only Numbers in order to accept only numbers as input and in your web.config enable client validation

hope this will help you

regards

Community
  • 1
  • 1
Monah
  • 6,714
  • 6
  • 22
  • 52