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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:24:33+00:00 2026-05-25T21:24:33+00:00

I am checking numeric value for one textbox like this: function validateNumeric() { var

  • 0

I am checking numeric value for one textbox like this:

function validateNumeric() {
    var old = document.getElementById("tbNum").value;
    var new = old_val.replace(/^\s+|\s+$/g,"");
    var validChars = '0123456789'; 

    for(var i = 0; i < new.length; i++){ 
        if(validChars.indexOf(new.charAt(i)) == -1){
        alert('Please enter valid number');
        return false; 
        }
    }
    document.getElementById("tbNum").value = new;
    return true; 
}

I want to use the same function and check numeric value for other text boxes that requires numeric value. How can I pass value of tbID, tbDiscID, as well as above and return true before submitting the form.

  • 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-25T21:24:34+00:00Added an answer on May 25, 2026 at 9:24 pm

    I am not sure what you mean by tbId and tbDiscID, but to do this in plain JavaScript, you can generalize this solution by traversing JavaScript’s arguments object, which lets you pass in any variable number of arguments to your function. This will help you take in the IDs you need. Your new solution would look something like the following:

    function validateNumeric() {
        for (var arg in arguments) {
            var id = arguments[arg];
            var old = document.getElementById(id).value;
            var new = old_val.replace(/^\s+|\s+$/g,"");
            var validChars = '0123456789'; 
    
            for(var i = 0; i < new.length; i++){ 
                if(validChars.indexOf(new.charAt(i)) == -1){
                alert('Please enter valid number');
                return false; 
                }
            }
            document.getElementById(id).value = new;
            return true;
        } 
    }
    

    Then invoke it like:

    validateNumeric("myTextbox1", "myTextbox2", ..., "myTextboxN");
    

    Where myTextBox1 … myTextBoxN are the IDs of your textboxes.

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

Sidebar

Related Questions

Checking few RDBMS I find that things like SELECT COUNT (a), SUM (b) FROM
I am just checking out F#, so apologies if this is a silly question,
I'm trying to create an associative array like this: $key = '0' $arr =
Checking function takes two arguments, I want to have a testcase for each element
I have a Python function that takes a numeric argument that must be an
Sometimes checking of arguments in Python is necessary. e.g. I have a function which
checking this sample. http://html5demos.com/drag i was wonder how to get when You drop a
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update
Checking the HTML source of a question I see for instance: <a id=comments-link-xxxxx class=comments-link>add
Checking to see if __name__ == '__main__' is a common idiom to run some

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.