Textbox to take only decimal values

Posted by Lalitha86 under JavaScript on 9/11/2012 | Points: 10 | Views : 1605 | Status : [Member] | Replies : 1
want a java script to check the text box value is decimal or not urgent




Responses

Posted by: Tanujad on: 9/11/2012 [Member] Starter | Points: 25

Up
0
Down
You can check the textbox value whether it is decimal or not as shown below --

<script type="text/javascript">  


function IsNoDecimal(str) {
if (isNaN(str) || str.indexOf(".") < 0) {
alert("Invalid");
}
else {
str = parseFloat(str);
alert("Entered number is decimal")
}
}

function ValidateInput() {
var txtBox = document.getElementById('TextBox1');
var txtboxValue = document.getElementById('TextBox1').value;
if (txtboxValue == "") {
alert("Please enter.");
txtBox.focus();
return false;
}
if (IsNoDecimal(txtboxValue) == false) {
// num = "";
txtBox.focus();
return false;
}
return true;
}
</script>


The ValidateInput javascript function can be called on a button client click event as shown below --

<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return ValidateInput();" />
</div>


Thanks
Tanuja
(If this content helped you, Please mark it as Answer)

Lalitha86, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response