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 3481530
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:27:29+00:00 2026-05-18T10:27:29+00:00

The problem: Limit allowed characters in a HTML input to a-z A-Z only. For

  • 0

The problem:

  • Limit allowed characters in a HTML input to a-z A-Z only.
  • For business requirements this needs to be done on KeyPress so that the character simply isnt allowed to even appear in the input.
  • Tab, enter, arrows, backspace, shift are all allowed. The user must be able to freely move in and out of the textbox, delete characters etc etc.

This is the starting point of my code…

var keyCode = (e.keyCode ? e.keyCode : e.which);

However every value that I get in keyCode doesnt correspond to any of the character charts I have seen on the web. For example the character “h” gives me a return code of 104.

Is KeyCode different to CharCode? Which code contains the control characters? Do I need to convert?

How can I restrict the input to a-z A-Z and allow the keys I need in JavaScript?

  • 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-05-18T10:27:30+00:00Added an answer on May 18, 2026 at 10:27 am

    The answers to all your questions can be found on the following page.

    …but in summary:

    • The only event from which you can reliably obtain character information (as opposed to key code information) is the keypress event.
    • In the keypress event, all browsers except IE <= 8 store the character code in the event’s which property. Most but not all of these browsers also store the character code in the charCode property.
    • In the keypress event, IE <= 8 stores the character code in the keyCode property.

    This means to get the character code corresponding to the keypress, the following will work everywhere, assuming a keypress event object is stored in a variable called e:

    var charCode = (typeof e.which == "number") ? e.which : e.keyCode
    

    This will generally return you a character code where one exists and 0 otherwise. There are a few cases where you’ll get a non-zero value when you shouldn’t:

    • In Opera < 10.50 for keys Insert, Delete, Home and End
    • In recent versions of Konqueror for non-character keys.

    The workaround for the first problem is a little involved and requires using the keydown event as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.