hi dear,
try below function.
Please remember that you have to call this function on keypress event of text box
function ValidDecimalPrice(textBox, evt) {
var txtPrice = document.getElementById(textBox);
var valPrice = txtPrice.value;
if (navigator.appName.toLowerCase() == "microsoft internet explorer") {
evt = evt || window.event;
var charCode = evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46)) {
event.ValidDecimalPrice ? event.ValidDecimalPrice() : event.returnValue = false;
}
if (charCode == 46 && valPrice.indexOf('.') > -1) {
event.ValidDecimalPrice ? event.ValidDecimalPrice() : event.returnValue = false;
}
if (charCode == 46 && valPrice == "") {
txtPrice.value = "0.";
event.ValidDecimalPrice ? event.ValidDecimalPrice() : event.returnValue = false;
}
}
else {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46)) {
return false;
}
if (charCode == 46 && valPrice.indexOf('.') > -1) {
return false;
}
if (charCode == 46 && valPrice == "") {
txtPrice.value = "0.";
return false;
}
}
return true;
}
Example for call it in C#
myTextBox.Attributes.Add("OnKeyPress", "return ValidDecimalPrice('" + myTextBox.ClientID + "',event);");
enjoy it