cfinput float validation allowing commas

Posted on 2007-10-15
Last Modified: 2013-12-24
Hi, I need a solution with answers.

I have five fields that are set to float in the SQL DB.  I want the user to be able to enter numbers, commas, decimals, and negative numbers only. If anything else is entered I want an alert message to popup. However none of these invalid characters will be saved to the DB. So I have this in the action page: <cfset total_dart=#ReReplaceNoCase(total_dart,"[$|,|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|!|@|%|^|&|*|(|)|\|/|]","","all")#>

And this is what the user will see for viewing purposes <cfif isDefined('form.total_dart2')><font color="##FF0000"> <strong>Don't Know </strong></font> <cfelseif  total_dart is ""> <font color="##FF0000"> <strong>No Response</strong> </font><cfelse>#numberformat(total_dart)#</cfif>

 I want to be able to use a cfinput. I also want to know should I use a CF reg expression or JS. Or can I combine both? I would really like to use CF only.

Heres what I have now for one field.
<cfinput  type="text" name=recinj  validate="float" validateat="onsubmit" message="Please enter numbers only, in Total Recordables" size="15" maxlength="20" value="#recinj#">
Question by:FIATECH
    LVL 5

    Accepted Solution

    Since the cfform data validation is really JS on the client side; the best practice is to do data validation on the client AND again on the server side by striping out any unwanted/illegal characters before sending them to the database.  

    The validate function is good with floats, one thing to keep in mind from a user stand point is that when dealing with larger numbers (say anything over 10,000.00 it is a lot simpler to read it that way vs. 10000.00).  You might think about using the regular expression validation to check to allow all numeric characters along with the period and comma and then strip them out using your RE on the server side.


    Author Comment

    Thanks, I'm reading up on regex
    LVL 14

    Expert Comment

    The cfinput you have with the validate="float" will allow commas, periods, and decimal places. so combining that with stripping out the commas and other illegal characters on the server side (and preferrably using cfqueryparam in your query) should have you in pretty good shape.

    Author Comment

    no it's not allowing commas

    Author Comment

    I'm using 6.1 if that's a problem

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now