Determining if a var is a number

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default Determining if a var is a number

    This probably is a simple problem but I have been struggling with it for some
    time. I am trying to determine if a user supplied variable is a number. The
    user inputs a value (their age) in an input text box. This means the value is
    of type 'String". Using various functions, such as typeof, parseInt and the
    Number object I can get a return of NaN if the value is not a number. However I
    simply cannot use the return in an if statement eg if (age == NaN) of if(age ==
    'NaN') just simply does not evaluate.

    Any suggestions?

    mitsubishi Guest

  2. Similar Questions and Discussions

    1. int Number to text Number Function / UDF ?
      Is there a function that converts e.g. 3 to Three? Probably not but I just thought I'd ask.
    2. determining roles
      Hi all, I'm creating a web application that attempts to restrict access by checking the IsInRole function for the desired roles. This works for...
    3. Determining OS in director
      Does anyone know how to determine whether os is Mac OSX + or below or windows?
    4. sort from the smallest number to the highest number
      Hi Just say I want to sort the row by using the fifth column data as reference from the smallest the largest number, if using sort, It will give...
    5. Determining Coverage
      A co-worker was finally able to dig it up in some notes from a class. The equation is 255 - (histogram mean value) / 255 = % coverage. Hopefully...
  3. #2

    Default Re: Determining if a var is a number

    Look up how to use isNaN().

    Jim
    "mitsubishi" <webforumsuser@macromedia.com> wrote in message
    news:c284tb$f3d$1@forums.macromedia.com...
    > This probably is a simple problem but I have been struggling with it for
    some
    > time. I am trying to determine if a user supplied variable is a number.
    The
    > user inputs a value (their age) in an input text box. This means the value
    is
    > of type 'String". Using various functions, such as typeof, parseInt and
    the
    > Number object I can get a return of NaN if the value is not a number.
    However I
    > simply cannot use the return in an if statement eg if (age == NaN) of
    if(age ==
    > 'NaN') just simply does not evaluate.
    >
    > Any suggestions?
    >

    James Fee Guest

  4. #3

    Default Re: Determining if a var is a number

    "mitsubishi" <webforumsuser@macromedia.com> wrote in message
    news:c284tb$f3d$1@forums.macromedia.com...
    > This probably is a simple problem but I have been struggling with it for
    some
    > time. I am trying to determine if a user supplied variable is a number.
    The
    > user inputs a value (their age) in an input text box. This means the value
    is
    > of type 'String". Using various functions, such as typeof, parseInt and
    the
    > Number object I can get a return of NaN if the value is not a number.
    However I
    > simply cannot use the return in an if statement eg if (age == NaN) of
    if(age ==
    > 'NaN') just simply does not evaluate.
    >
    > Any suggestions?
    >
    You can restrict the input to numbers only...
    Example: input text box named agebox:
    agebox.restrict = "0-9";

    Here is restriction for alpha letters only...
    agebox.restrict = "a-z A-Z";

    Here is restriction for letters and numbers only without punctuation etc..
    agebox.restrict = "a-z A-Z 0-9";

    If the number of chars input is 0, don't evaluate it.
    hth
    tralfaz


    tralfaz Guest

  5. #4

    Default Re: Determining if a var is a number

    BTW.. If you prefer not to use actionscript, you can also restrict the input
    text box to numerals only by selecting properties for the input text box:
    Properties..
    Character button...
    Check mark ONLY..
    Check mark Numerals (0-9)
    tralfaz

    > You can restrict the input to numbers only...
    > Example: input text box named agebox:
    > agebox.restrict = "0-9";
    >
    > Here is restriction for alpha letters only...
    > agebox.restrict = "a-z A-Z";
    >
    > Here is restriction for letters and numbers only without punctuation etc..
    > agebox.restrict = "a-z A-Z 0-9";
    >
    > If the number of chars input is 0, don't evaluate it.
    > hth
    > tralfaz

    tralfaz Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139