I have a textbox and I need to let user enter only amount of money, which means only numbers and a ma
here is what I have
<asp:TextBox ID="txt_tutar" runat="server" onkeypress="this.value=this.value.replace(/\D/g,'')"></asp:TextBox>
this code above only allows numeric, it deletes the ma. how can I update to let user enter float number in textbox ?
I have a textbox and I need to let user enter only amount of money, which means only numbers and a ma
here is what I have
<asp:TextBox ID="txt_tutar" runat="server" onkeypress="this.value=this.value.replace(/\D/g,'')"></asp:TextBox>
this code above only allows numeric, it deletes the ma. how can I update to let user enter float number in textbox ?
Share Improve this question edited Jun 26, 2013 at 19:09 Ian 51k13 gold badges104 silver badges111 bronze badges asked Jun 26, 2013 at 19:07 Arif YILMAZArif YILMAZ 5,88629 gold badges114 silver badges197 bronze badges 02 Answers
Reset to default 5Use this regular expression:
/[^\d,]/g
As in:
this.value=this.value.replace(/[^\d,]/g,'')
Of course this doesn't really mean the string will be a valid numeric value; e.g. 2,,0,1
would be considered fine. You really should be doing full server-side validation using decimal.TryParse
or something similar
Here you can also use required field validator to do ths,
Better way go with javascript at client side for performance, use below script
function isValidNo(str) {
var inbadChars = "\t\n\r^&*=~`';<>?[]{}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
//debugger;
for (n = 0; n < str.length; n++) //filter for invalid chars
{
if (inbadChars.indexOf(str.charAt(n)) != -1) return false;
}
return true;
}
Reended to use server side tryparse as well, as on somebrowser sometimes scripets may not work.