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

  • Home
  • SEARCH
  • 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 7080677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:49:29+00:00 2026-05-28T06:49:29+00:00

I am working in Javascript. I am trying to make a function on the

  • 0

I am working in Javascript. I am trying to make a function on the keypress event. I want to make function for validation on mobile number. I want to allow only digits in it. I also want to allow ctrl+v and ctrl+a in this but I dont want to allow V and A as characters.

I have seen many answers here but no one is purely same.

  • 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-28T06:49:29+00:00Added an answer on May 28, 2026 at 6:49 am

    If you only care that digits are entered, as it seems from your question, this Jquery code will work.

    It uses on keyup() and thus it will work on ctrl+v as well. It won’t work if someone uses right-click to paste, and for that reason, you can just disable right clicking on that field.

    It works by stripping off the last character of the input value if it is not a number. So if a user enters 25s or 25ss, it will get stripped down to 25.

    Live Demo

    The Jquery

    $(document).ready(function(){
        $('#number').keyup(function(){    
            var input = this.value;
            while (isNaN(input))
            {
                input = input.substring(0,input.length-1);
                $('#number').val(input);             
            }
        });
        //disable right click on the field
        $('#number').bind("contextmenu",function(e){
            return false;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to make a JavaScript function for a Google Chrome web-application that
I'm trying to make a working JS function which ought to add some text
I am working with javascript and here is what I am trying to do:
I'm trying to get a case-insensitive search with two strings in JavaScript working. Normally
I am trying to get a better working knowledge of JavaScript. So, I have
I'm working on an interactive interface using SVG and JavaScript/jQuery, and I'm trying to
I'm working on a JavaScript image resizing feature which rely on the IE only
I am working on a JavaScript utility that tells the user the number of
I'm trying to make a JavaScript bookmarklet that will act as a highlighter, changing
hey, Im trying to make a call a jquery function and pass some args

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.