• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

Coldfusion server side validation decimal-number

Hello experts.
I need help to validate a textfield and allow number with decimals without using jacascript.The code below is validating if it is a anumber with postive values but it does not allow decimal values(f.e 12,25).
Any help to fix this?
<cfif Form.Submitted EQ 1>
  <cfif Form.Prozent NEQ "">
  <cfif NOT IsNumeric(Form.Prozent) OR   Form.Prozent LTE 0>
    <cfset errors = errors & "Bitte eine postive Nummer  ins Prozent-Feld eingeben! (z.B 12,50)<br>">
    <cfset ProzentError = 1>
<input name="prozent" type="text" <cfif ProzentError EQ 1> class="textfieldprozentwarn"<cfelse>class="textfieldprozent" </cfif> id="prozent" maxlength="5"  value="<cfoutput>#Form.Prozent#</cfoutput>"/>
<input  name="INSERT" type="submit">
                       <input  name="submitted" type="hidden" value="1" />

Open in new window

  • 4
  • 2
1 Solution
Dear panosms,

check out the ColdFusion Function LSParseNumber ( http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa38.htm ) as you are trying to input german numeric values.

This should work.
Hope that helps.
PanosAuthor Commented:
On this site:http://tutorial201.easycfm.com/
i found a tag named ListValueCount.I have not make it work yet.
I will try it tomorrow again.Can you take a look too?
PanosAuthor Commented:
Hi eclipse2k.
I will keep the 34.34 format.
So i don't need the german numeric values.
Thank you for your help.
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

PanosAuthor Commented:
thank you again
Hey panosms,

The Function (not a tag) named "ListValueCount" is a basic ColdFusion tag, you can find more information here: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functb22.htm

which ColdFusion version are you using? I don't see any problems using that function.

Please note that the tutorial at the page you mentioned above is very old (2003) and the technique used is old too, as it was designed for ColdFusion versions prior to 6.1. When you are using a modern ColdFusion version like MX 7 oder CF 8, you should check out this much more advanced techniques:


PanosAuthor Commented:
Hi eclipse2k:
I had two problems.The first to allow only postive number values without any , or .
and the other to allow positive numbers that allow (,) and not (.)
so for the first i find out that the code that is checking what i want is:
<cfif NOT IsNumeric(Form.Test) OR NOT IsValid('integer',Form.Test) OR   Form.Test LTE 0>
    <cfset errors = errors & "....blabla....">
    <cfset TestError = 1>
For the second i decided to use the format with a (.) as i saw that the IsNumeric format ia checking this.
I did not find out how to check how many decimals to allow.
Well if you want to make a comment about all these i would be very happy.!!

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now