Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:02:36+00:00 2026-06-11T08:02:36+00:00

i wanted to Allow only Numbers in text box using jquery/javascript with out extra

  • 0

i wanted to Allow only Numbers in text box using jquery/javascript with out extra plugins

I have coded like :

if ( event.keyCode == 46 || event.keyCode == 8 || (event.keyCode >=48 && event.keyCode <=57)) {
            // let it happen, don't do anything
        }
        else {
            // Ensure that it is a number and stop the keypress           
            event.preventDefault();                   
        }

but it allows special characters like ! (Shift+1), @ (shift +2) etc.

can any body tell me the complete solution for this .. thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:02:38+00:00Added an answer on June 11, 2026 at 8:02 am

    I solved by using the below code snippet. thanks for the inputs and help

    $('input[etype="Number"]').keydown(function(event) {
    
         if(event.shiftKey && ((event.keyCode >=48 && event.keyCode <=57) 
                 || (event.keyCode >=186 &&  event.keyCode <=222))){
            // Ensure that it is a number and stop the Special chars
             event.preventDefault();
         }
         else if ((event.shiftKey || event.ctrlKey) && (event.keyCode > 34 && event.keyCode < 40)){     
              // let it happen, don't do anything
         }      
         else{
            // Allow only backspace , delete, numbers               
            if (event.keyCode == 9 || event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 39 ||event.keyCode == 37 
                    || (event.keyCode >=48 && event.keyCode <=57)) {
                // let it happen, don't do anything
            }
            else {
               // Ensure that it is a number and stop the key press
                    event.preventDefault();                   
            }
         }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following NumberTextBox and i wanted to allow only the digits,but i
I just wanted to ask. I have text input to allow users to type
I wanted a text field to take only numbers ans some control keys and
I have created a regex that only allows the user to enter numbers and
I wanted to know how to send e-mail using javascript. I dont want to
I wanted to allow only characters in a textbox and space in between two
I wanted to allow only specific email domain. Actually I did it. What i
I have a container that holds a chart and I wanted to allow the
I wanted to allow users to be able to add videos but I'm having
I wanted to allow for a method to get called, if a finger was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.