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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:54:50+00:00 2026-06-06T07:54:50+00:00

I cannot handle properly some events in input type=text . I just need a

  • 0

I cannot handle properly some events in input type=”text”.
I just need a filter to only accept [^0-9] chars.

I need the following help:

  • Do not accept any content coming from Control + Paste command. Either from Control+V (keyboard) or Right click mouse + Paste Option.

What i tried so far:

  • keypress event i handle nicely any input from keyboard. (any chars not in [^0-9] and enter, backspace, home, end, etc will be simply ignored).

  • keyup i handle weirdly Control + Paste (keyboard) event.
    I paste some string, and after the string is pasted, i crop any non-white list chars.
    PS:
    BUT this don’t work with Right Click + Paste (mouse), neither

  • onChange the garbage string stay visible until the user blur the field.

What i want:

  • Copy the example string “123.321.456-78” and paste “12332145678” or “abc!2¨#7” and paste “27”.

  • Do not accept any non-white list chars from any possible way. (even with $(‘#field’).val(“trash input 123”).

From all problems above, i can handle nicely or weirdly (aka: keuup) the input, but Right Click + Paste (mouse) NEVER trigger ANY EVENT so i can do the properly treatment.

I thought about doing Interval Check, but this is too ugly.

EDIT:

Code below

function soNumeroInteiro_keypressHandler(event)
{
    var code = event.keyCode || event.which;

    switch(code)
    {
        case  8: // backspace
        case 37: // left
        case 39: // right
        case  9: // tab
        case 46: // delete
        case 35: // end
        case 36: // home
            return true;
        break; 

        case  86: // control + A
        case  97: // control + V
        case 120: // control + X
            if (event.ctrlKey) {
                return true;                
            }
        break;
    }

    var tecla = String.fromCharCode(code);

    return tecla.match(/^\d$/) != null;
}

function soNumeroInteiro_keyupHandler(event)
{
    event.currentTarget.value = event.currentTarget.value.replace(/[^0-9]/g, '');
}
  • 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-06T07:54:51+00:00Added an answer on June 6, 2026 at 7:54 am

    Please see this question for the mouse click events: How to distinguish between left and right mouse click with jQuery

    NOW you have the mouse click event, even the right click, you can then poll the content for a short bit (2 seconds?) to detect changes and handle the content validation. This way, you COULD choose to either accept valid or reject the content based on your business logic needs.

    EDIT:
    Just to add a note, the onpaste event will not work correctly in that it will fire (in some test cases at least) prior to the content being pasted.

    Example:

    $('#pasteyMe').on('paste', function() {
        $(this).val();// gets the content prior to the paste event
    });
    

    To work around this, you could set another event watcher such as change and then fire that:

    $('#pasteyMe').on('click focus blur paste', function() {
        var me = this;
        window.setTimeout(function() {
           $(me).trigger('change');
        }, 1);
    });
    
    $('#pasteyMe').change(function() {
        $('#resulty').text($(this).val());
    });
    

    See this in action here: http://jsfiddle.net/MarkSchultheiss/kQxAj/

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

Sidebar

Related Questions

I'm working updating some legacy code that does not properly handle user input. The
I use twitter4j library to tweet but i cannot handle how to upload an
I cannot say I have a strong C++ background so I hear Handle very
Why Nibernate HQL can not handle the following query: from Deal D where (D.ApprovalDate
How to properly handle listview's last column sizing in such a way that: listview
I have the following basic code to read a text file from a StreamReader:
I have created the following subclass to do some custom drawing: // DocumentIconView.h @interface
I am running an application on Ruby On Rails (3.1) and need to handle
Hello I need to group some Dropdown lists in ASP.NET form.So I wanted to
I'm using the ADO.Net Entity Framework. To handle input validation I'm trying to use

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.