Implementing Digits restriction Using JQuery

Implementing Digits restriction Using JQuery

Hi Sir

I have following field in my html form :

<div>Age<input type="text" name="quantity" id="quantity" /></div>

I want to implement two things :

1 if the letter is not digit then display error and don't type anything

2 Age must be between 18 & 35 and it will show error when it is not in between age range.

Please provide code.

View Answers

December 15, 2010 at 12:55 PM

You can implement these two things using ASCII code & parseint method. Code is provided below :

//called when key is pressed in textbox
    $("#quantity").keypress(function (e)  
    { 
    $("#errmsg").hide();
      //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("&nbsp;&nbsp;Digits Only").show(); 
       return false;
      } 
      });
      $('#quantity').blur(function(a) {
      if((parseInt($("#quantity").val(), 10)<18)) 
      {
      $("#errmsg").html("&nbsp;&nbsp;Age must be greater than 18").show(); 

      }
      if((parseInt($("#quantity").val(), 10)>35)) 
      {
      $("#errmsg").html("&nbsp;&nbsp;Age must be less than 35").show(); 
      }
     });

Ads









Related Tutorials/Questions & Answers:
Implementing Digits restriction Using JQuery
Implementing Digits restriction Using JQuery  Hi Sir I have.... Please provide code.   You can implement these two things using ASCII code...("&nbsp;&nbsp;Digits Only").show(); return false
implementing an algorithm using multi threads - Java Beginners
implementing an algorithm using multi threads  Hi i need to implement an algorith in multi threads.Algorithm has data dependency so i need to pass data from one thread to another thread. I am posting my algorithm which needs
Advertisements
Vertical news slider using jquery
Vertical news slider using jquery  how to creatw vertical news slider using jquery Sorry for wrong category but i cant get my jquery category
Show Limited Data Using jquery
Show Limited Data Using jquery  How to show limited results in JQuery... it using JQuery?   See the JQuery example to show the limited fetch results in JQuery. var comments = $('.description_text').size(); if (comments >
Form validation Using Jquery Plugin
Form validation Using Jquery Plugin  Hello sir I want to implement form validation using JQuery Plug-in. My code is : <html> <style type...;/form> </body> </html> Please provide me JQuery code regarding
Html form validation using jquery
Html form validation using jquery  Hi i am using form with html. Form elements like textbox, radio,checkbox,listbox i was used now how to validate the elements using submit jquery option
HTML form validation using jquery
HTML form validation using jquery  Is there any way for validating html elements common under a class by giving its class name in jquery validation code..that means validating all elements by using its class name if those
Using the jQuery Transform plug-in(XSLT)
Using the jQuery Transform plug-in(XSLT)       Using the jQuery Transform plug-in(XSLT... Language Transformations ). The jQuery Plugin we are using
Disabling submit button using jQuery
Disabling submit button using jQuery  Hello Sir I want to know - is there any way or approach to disable client side form's "Submit" button. Please give code also.   For all submit buttons, via JQuery, it'd
application using AJAX and JQuery and also use JSP
application using AJAX and JQuery and also use JSP   i need create an application using AJAX and JQuery and also use JSP
Using the jQuery event object
Using the jQuery event object       Using the jQuery event object JQuery... to these standards, this system normalize the event object. jQuery. Event
Find Browser & it's version using jQuery
Find Browser & it's version using jQuery  Hi sir I heard that JQuery have some method which can be used to find the Browser name & its version. I need the code which checks the browser and if it is "Mozilla", it will show
How to write a search functionality using javascript/jquery
How to write a search functionality using javascript/jquery   How to write a search functionality using javascript/jquery for ex: im searching "s" names it wil display "s" names
Using the QUnit to test jQuery application
Using the QUnit to test jQuery application       Using the QUnit to test jQuery application Using Qunit , testing of JQuery become very easy and efficient
Crop image Using JQuery, servlet or JSP.
Crop image Using JQuery, servlet or JSP.  Hi sir I need the code of Cropping image using JQuery with the help of servlet or JSP. I need both the code Client side as well as of server side. Please Help me
check username availability using JSP & JQuery
check username availability using JSP & JQuery  Hi sir I want check username availability using JSP & JQuery. Please add code with your answer. Thnks in advance
Auto grow Text Area using jQuery plug-in
Auto grow Text Area using jQuery plug-in  Hi sir How can we make a textarea auto grow ? What is the name of the plug-in used for auto grow text area. Please mention code with your reply
Explain the process of implementing a CORBA client using a Java programming example and the steps involved.
Explain the process of implementing a CORBA client using a Java programming example and the steps involved.  plz tell me answer of this question... the process of implementing a CORBA client using a Java programming example
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
jQuery auto complete through database using JSP shows error
jQuery auto complete through database using JSP shows error  The tutorial on jQuery titled "jQuery auto complete through database using JSP" shows error on browser when I try to select the one in the dropdown. Please help
pdf restriction
pdf restriction  i have certain pdf files that have restrictions on it as copy ,read,extract text etc.. i want to remove restriction by java code. so is there any way to do this? plz help thanks in advance rohit
Creating, getting, and setting content using jQuery
Creating, getting, and setting content using jQuery... content using jQuery Using jQuery , you can add(create) html content... by using jQuery and also can modify it .For example, you can get
how to print HTML using javascript or Jquery
how to print HTML using javascript or Jquery  is there any way to print a document(created using Html and javascript) without using window.print, which works for all the browser specially chrome and firefox, I have used
Passing classid or name in request using Jquery
Passing classid or name in request using Jquery  Hi, I am new to JQuery.I have a servlet that I am calling using jquery.I have some parameters like filename,userid that I am passing to the servlet to upload a file.I have created
jquery
jquery  how to display the leaves taken or holidays of the year or half working days in a calendar in some colors to identify the days using jquery plugin
JQuery
JQuery  how to use jquery
multiply of 100 digits numbers
multiply of 100 digits numbers  multiplying 100 digits numbers to eachother
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Sir, Lots of thnx to ur reply .I went through both the tutorials... autocomplete textbox using jquery in jsp from mysql database. Kindly send me
JQuery
JQuery  how to create jquery auto-complete textbox ? in which data...://www.roseindia.net/tutorial/jquery/autoSuggestTextbox.html   thank you for fast reply. when i m using key-down than cursor is not going down.i m not able
Selecting value from autocomplete textbox using jquery in jsp
Selecting value from autocomplete textbox using jquery in jsp   hello Sir, I completed ur tutorial on autocompletion textbox from database using Jquery in jsp .It worked Fine .Thank you For Ur valuable Guidance .But it does
Jquery
Jquery  I am new to Jquery. Can anyone please tell me how to use jquery plugins in html
How to save form data to a csv file using jquery or ajax
How to save form data to a csv file using jquery or ajax  Please let..., Thank you for your reply , i am suppose to use only jquery or ajax for doing this. i am able to read the csv file using this code if (window.XMLHttpRequest
File Upload is working in FireFox & Chrome but not in IE7 using java & jquery
File Upload is working in FireFox & Chrome but not in IE7 using java..." and shows dialogue to select the file.After that I am calling Jquery function to upload that file.In my jquery I am calling a servlet for upload.The code
jquery
jquery  What are the Jquery similarities or difference with other java script libraries
java program_big digits multiplication..
java program_big digits multiplication..  i want program about big digits multiplication program using java..plz tel me answer
ModuleNotFoundError: No module named 'digits'
ModuleNotFoundError: No module named 'digits'  Hi, My Python... 'digits' How to remove the ModuleNotFoundError: No module named 'digits'... to install padas library. You can install digits python with following command
JQuery
JQuery  How i begin JQuery and where i begin learning?   Please visit the following link: JQuery Tutorials Learn Jquery from the above link. Here you will get lot of examples with illustration
JQuery
using url of the doctors, use jquery autocomplete
Implementing Interface
Implementing Interface  interface Mat { void read( ); void display( ); } Create a class Matrix by implementing interface Mat. Derive class MatrixOp from Matrix and provide functions to add and multiply two matrices. Also derive
jQuery
jQuery  Hi, What is jQuery and how it is used to develop Web applications? Thanks
How to add google page in my webpage using jquery ajax.
How to add google page in my webpage using jquery ajax.  Hi, I created a page index.html on desktop . this page content following code. <html>... not open on my browser. how google page will load using ajax. thanks
Implementing Vectors.
Implementing Vectors.  Create a class Student which stores Name ,Rollno and Grandtotal of a student. Use class Vector to maintain an array of students in the descending order of the Grand_total. Provide the following functions 1
accessing data from a json file writing javascript or using jQuery
accessing data from a json file writing javascript or using jQuery  I am trying to create a page from json objects using javascript. I have... the javascript or use jquery to get the page to display in the browser. I've tried
JQuery
, use jquery autocomplete
jQuery Demos
in different file Display current time using jQuery & JSP Selecting element using jQuery. Showing content of a file using JSP & jQuery Calculating square root using JSP & jQuery
jQuery plugin examples code
:  Form validation using jQuery plug in & JSP The 'innerfade' effect using jQuery plug-in The 'innerfade' effect with "Images" using jQuery plug
ModuleNotFoundError: No module named 'python-digits'
ModuleNotFoundError: No module named 'python-digits'  Hi, My... 'python-digits' How to remove the ModuleNotFoundError: No module named 'python-digits' error? Thanks   Hi, In your python
Implementing voice commands
Implementing voice commands  Am trying to write a java program to implement voice commands within a windows platform using preferably java (though any language will do). I would be glad for any tips and procedures that would help
jQuery - jQuery Tutorials and examples
created many examples of using jQuery. View the demo's here. Learn jQuery step by step using the following tutorials: Overview of jQuery..., getting, and setting content using jQuery Manipulating attributes

Ads