Jump to content

Checking numbers - is not a number query


richrock

Recommended Posts

Hi,

 

I'm doing some validation on a form, and just need to fine-tune one part of it -  the dates are entered numerically, eg 01-02-10, and want to ensure that a number is used for the date.  So I did this:

 

if (practitioner_month_referred == null || practitioner_month_referred == "" || practitioner_month_referred == "<?php echo $monval; ?>" || isNaN(practitioner_month_referred)) {
            if (focused == false ) {
                document.getElementById('practitioner_month_referred').focus();
                focused = true;
            }
            if(isNaN(practitioner_month_referred)) {
                numvalid = false;
            } else {
                numvalid = true;
            }
          document.getElementById('practitioner_month_referred').style.color="<?php echo $formcol_3; ?>";
          document.getElementById('practitioner_month_referred').style.fontWeight="bold";
          valid = false;
       }

 

But, it seems that if I type in 01 as a month in this example, is tells me that this is not a number (by the big red error message from numvalid being switched to false.

 

Is the isNaN right?  Or is there some other way of checking that it is in fact a number, not letters or anything else?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.