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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:52:52+00:00 2026-05-24T08:52:52+00:00

I am doing some form validation on a project with javascript. what im doing

  • 0

I am doing some form validation on a project with javascript. what im doing works but it seems like there might be a better way to do it. here is an example of what i have.

onkeypress="return keyNumOnly(event)"
function keyNumOnly(key)
{//this allows numbers and decimals.   
    var keychar;
    var numcheck;
    var keynum;
    if(window.event) // IE
        {
            keynum = key.keyCode;
        }     
    else if(key.which) // Netscape/Firefox/Opera
        {
            keynum = key.which;
        }
    if (keynum==8)
        {
            return true;
        }
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    if (keychar== ".")
        {
            return true;    
        }
    return numcheck.test(keychar);
}
  • 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-24T08:52:53+00:00Added an answer on May 24, 2026 at 8:52 am

    Some cleanup:

    someTextbox.onkeypress = function(event) { // you can pass a function directly
        var event    = event || window.event, 
            // this means: event or window.event if event does not exist
    
            keynum   = event.keyCode || event.which,
            // event.keyCode or event.which otherwise
    
            keychar  = String.fromCharCode(keynum),
    
            numcheck = /\d/;
    
    
        if(/\t|\./.test(keychar)) {
            // checking for dot or tab using a regexp: \t is tab, | means 'or', \. is dot
            return true;
        }
    
    
        return numcheck.test(keychar);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing some basic form validation. I have the following JavaScript function: function
i am doing jquery form validation, then i searched online for some answers like
For example, if I'm doing some form input validation and I'm using the following
Im doing some form validation on a website and I've tried to use JQuery
i'm trying to put together some Javascript form validation to check that all fields
i'm doing a JSF2 project. 1 . i have a form with some checkbox.
I'm doing some spring form validation, however I'm getting: Failed to convert property value
Trying to do some javascript form validation through JQuery and a Validation plugin. I'm
I'm doing some form validation, and I'm having trouble with what I'm trying to
I am doing some server side form validation and in the case that one

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.