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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:33:06+00:00 2026-06-01T20:33:06+00:00

Most web developers know that to restrict only numbers to a form input, you

  • 0

Most web developers know that to restrict only numbers to a form input, you can do something like this:

$(function() {
    $("#foobar").keypress(function(e) {
    if($.inArray(e.which, range(48, 57)) == -1) {
        e.preventDefault();
        return false;
    }
    });
});

function range(start, end) {
    var range = [];

    for(var i = start; i <= end; i++) {
        range.push(i);
    }

    return range;
}

Unfortunately, this does not quite get the job done on an Android with the default browser. (iPhone and Other Android browsers have not been tested, so they could suffer from the same issue. Tested on an iPhone 4S, which did not have this issue.)

On an Android, let’s say you first type “f”. Nothing happens. Awesome. Wait just a minute. You then type “a”. What happens? The “f” is put into the input field! You type “c”, the “a” is put into the field. And so on. Whatever the previously-entered character is, that’s what’s put into the field.

Here’s a jsFiddle that demonstrates the issue.

The fiddle works fine on a desktop, but try it on Android (phone or emulator). I’ve tested with Android 2.3.6 and 2.2.

Anyone run into this before? Any direction would be greatly appreciated! For now, the workaround is to remove non-numeric characters immediately afterwards (in the keyup event).

Update: Here is a fiddle that shows that preventDefault() is being reached. The problem seems to be that rather than preventing, it’s simply delaying (until the next event).

  • 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-01T20:33:08+00:00Added an answer on June 1, 2026 at 8:33 pm

    A completely different approach would be using <input type="number"> and relying on the browser to provide the appropriate interface/filtering (which mobile browsers are prone to). It does not fix the code, but should circumvent the problem, which looks like a bug, to be honest.

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

Sidebar

Related Questions

Like most web developers these days, I'm thoroughly enjoying the benefits of solid MVC
I'm building a web application that is aimed at developers. I assumed that most
Most web browsers support only HTTP methods like GET and POST and do not
Over the years most web developers will have built an arsenal of tools or
I use Eclipse Java EE IDE for Web Developers for most of my coding,
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I
So far in my web developing experiences, I've noticed that almost all web developers/designers
I'm working on a web application that is most likely going to end up
As many developers will be I'm producing web based application that are using AJAX
Like many developers working on web sites for Internet Explorer, I seem to come

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.