Tuesday, November 4, 2014

jquery numeric validation

Posted by Gnani Palepu  |  3 comments

 Textbox accepts only numbers:    
 ----------------------------  
 HTML  
 -----  
 Number : <input type="text" name="quantity" id="quantity" />&nbsp;<span id="errmsg"></span>  
 jquery  
 ------  
 $(document).ready(function () {  
  //called when key is pressed in textbox  
  $("#quantity").keypress(function (e) {  
    //if the letter is not digit then display error and don't type anything  
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {  
     //display error message  
     $("#errmsg").html("Digits Only").show().fadeOut("slow");  
         return false;  
   }  
   });  
 });  
 css  
 ------  
 #errmsg  
 {  
 color: red;  
 }  
 jquery numeric input  

12:50 AM Share:

3 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top