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 values.
How can i do?
I think jquery could help me...but...what's the id of that textbox?
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 == '.' )
return true;
return false;
}
And regarding Id, you can do it via class as well.
In your case it will be
@class = "alignRight"
Also from http://www.webdeveloper.com/forum/showthread.php?124756-Stop-pasting-of-invalid-text-into-decimal-only-textbox.
function validateDecimal(textboxIn)
{
var text = textboxIn.value
for(var x = 0; x < 10; x++)
{
while(text.indexOf(x) != -1)
{
text = text.replace(x,"");
}
}
if(text != "." && text != "")
{
textboxIn.value = "";
}
}