.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Javascript validate Numeric value with negative and decimals

Posted By:Amit Mehra       Posted Date: March 26, 2010    Points: 10    Category: Javascript    URL: http://www.dotnetspark.com  

JavaScript Validation for accepting Numeric value with decimal and negative value.

This JavaScript function will allow user to enter numeric value with decimal places and also allow negative sign.

This JavaScript function you can all in onkeypress event of the textbox and it will validate the user entered value in client side.

This function will also allow back space key on the textbox if user want to remove some value using BackSpace key

function allowNegativeNumber(e) 
            var charCode = (e.which) ? e.which : event.keyCode
 if (charCode > 31 && (charCode < 45 || charCode > 57 )) { return false; } return true; }



Further Readings:

Author: Jimson         Company URL: http://www.dotnetspark.com
Posted Date: March 30, 2010

how i can check the return value is true or not?
Author: Amit Mehra         Company URL: http://www.dotnetspark.com
Posted Date: March 31, 2010

Hi Jimson,

We are using this statement onkeypress="return allowNegativeNumber(event); onkeypress event and if you see the JavaScript code we are returning True or false so we will know weather its true or false.

Is that answer your question? if not please reply.


Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend