Force Input To Be Decimal In @html.textbox
i have a problem. I have a Razor Textbox: @Html.TextBox('imp', amount, new { @class = 'alignRight', size = 5 }) I would like that , in input, user will write only decimal value
Solution 1:
Yes you can do via Jquery and Javascript as well
function isNumeric(evt)
{
var c = (evt.which) ? evt.which : event.keyCode
if ((c >= '0' && c <= '9') || c == '.' )
returntrue;
returnfalse;
}
And regarding Id, you can do it via class as well. In your case it will be
@class = "alignRight"
function validateDecimal(textboxIn)
{
var text = textboxIn.valuefor(var x = 0; x < 10; x++)
{
while(text.indexOf(x) != -1)
{
text = text.replace(x,"");
}
}
if(text != "." && text != "")
{
textboxIn.value = "";
}
}
Post a Comment for "Force Input To Be Decimal In @html.textbox"