Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

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>
  </cfif>
 </cfif>
</cfif>
<form>
<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" />
</form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of eclipse2k
eclipse2k

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi.
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?
Avatar of Panos

ASKER

Hi eclipse2k.
I will keep the 34.34 format.
So i don't need the german numeric values.
Thank you for your help.
Avatar of Panos

ASKER

thank you again
regards
panos
Avatar of eclipse2k
eclipse2k

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:

http://www.bennadel.com/blog/1041-Exercise-List-Error-Collection-ColdFusion-Component.htm
http://mattosbun.sys-con.com/node/370835

greetings,
thomas
Avatar of Panos

ASKER

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>
  </cfif>
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.!!