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


Top 5 Contributors of the Month
david stephan

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

 Subscribe to Code Snippets

Number only

Posted By:shahin       Posted Date: November 03, 2008    Points: 10    Category: Javascript    URL: http://www.dotnetspark.com  
 

Below is the code to accept Number only in textbox. With this you can retrict user to enter only numeric value using javascript. You can call this function on "onkeypress" of textbox

  1. function isOnlyNumberKey(evt)
  2. {
  3.    var charCode = (evt.which) ? evt.which : event.keyCode;
  4.    if (charCode > 31 && (charCode < 48 || charCode > 57))
  5.    {
  6.     window.event.keyCode = 0;
  7.     return false;
  8.    }
  9.    else
  10.     return true;
  11. }


     

Further Readings:

Responses

No response found. Be the first to respond this post

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