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
https://forums.phpfreaks.com/topic/195781-checking-numbers-is-not-a-number-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.