Easy validation question

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default Easy validation question

    hey all,

    I am getting an error on my page. It is doing a calculation so the input must
    be a number. It throws an error if the number has a comma in it. How can I
    avoid this?

    ERROR:
    An error occurred while evaluating the expression:

    paymt=(url.prin)*i/(1-temp)

    Error near line 158, column 9.

    Cannot convert 100,000 to number.

    Please, check the ColdFusion manual for the allowed conversions between data
    types

    rbgerman Guest

  2. Similar Questions and Discussions

    1. VERY easy question (I think!)...
      Regarding this page I'm working on: http://al-i.anixter.com/TEMP/SAM/index.html I can't get the text to all be to the right of the pictures. ...
    2. Easy question, but not for me :)
      Hi, I've got a dilemma. I want a Flash-website, but don't really understand how should I implement it. Example: a movie playing in the center and...
    3. Easy question = easy answer?
      Well, so I'm pretty new with Freehand, at the mo running with MX and havin' a problem (not big, but anyway)... I'm creating some cards and they...
    4. Easy Question ??
      Hi Renee, You first want to add the field to the underlying table. Then when you go to your form, the field list will include that new element and...
    5. Easy Question/Easy Answer
      Ok, this is all i want to know how to do, i made a text link, now when someone rolls over it with their pointer i want it to change color. Simple?
  3. #2

    Default Re: Easy validation question

    I wrote a UDF for this purpose which converts valid numbers (numbers with
    commas and up to one decimal) to numeric values (at bottom of message). You can
    also use the UDF, [url]http://www.cflib.org/udf.cfm?ID=707[/url] to remove all non-numeric
    chracters - thereby forcing a numeric value.

    Others may recommend val(), but be careful with that for this problem as it
    returns the first numeric characters (it would return the numbers *before* the
    first comma).

    <cfscript>
    function convertNumber(strNumber) {
    var i = 0;
    var tmpVal = "";
    var thisChar = "";
    var dotCount = 0;
    for (i=1; i lte Len(strNumber); i=i+1) {
    thisChar = Mid(strNumber, i, 1);
    if ( isNumeric(thisChar) OR thisChar eq "." ) {
    tmpVal = tmpVal & thisChar;
    } else {
    if ( thisChar eq "." AND dotCount eq 0 ) {
    dotCount = dotCount + 1;
    tmpVal = tmpVal & thisChar;
    }
    }
    }
    if ( Len(tmpVal) eq 0 ) {
    tmpVal = 0;
    }
    return tmpVal;
    }
    </cfscript>

    SteveBryant Guest

  4. #3

    Default Re: Easy validation question

    It's probably easier to use replace() to get rid of the comma's. If there is any doubt as to whether or not the url variable is a number, isNumeric() can be used to check.
    Dan Bracuk Guest

  5. #4

    Default Re: Easy validation question

    you can also start out with the form so it only accepts a numeric entry using the validation techniques for forms
    SafariTECH 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