Javascript function to enter decimal only

Posted by Anumary under JavaScript on 4/26/2012 | Points: 10 | Views : 1647 | Status : [Member] | Replies : 2
Can any1 send me the javascript code to enter decimal values upto 2 places?Their should be a value , otherwise it should be 0.00.The function should not allow alphabets & negative numbers.




Responses

Posted by: Sabarimahesh on: 4/26/2012 [Member] Bronze | Points: 25

Up
0
Down
http://amitchandnz.wordpress.com/2010/08/17/function-to-only-accept-numeric-values/

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Posted by: Somasundaram on: 4/27/2012 [Member] Starter | Points: 25

Up
0
Down
<script language="javascript" type="text/javascript">
function validate()
{
var exp = /^[0-9]\d*(\.\d+)?$/;
var Quantity=document.getElementById('<%=this.txtQuantity.ClientID %>').value;
if(Quantity != "")
{
if(!Quantity.match(exp))
{
alert('Please Enter only Numbers in Quantity');
return false;
}
}
</script>

Call the Function in Button Click:
<asp:Button ID="btnSubmit" runat="server" OnClick="Submit_click" Text="SUBMIT" OnClientClick="return validate()"/>

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

Login to post response