cfinput float validation allowing commas

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#">
Who is Participating?
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.

FIATECHAuthor Commented:
Thanks, I'm reading up on regex
Scott BennettManager TechnologyCommented:
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.
FIATECHAuthor Commented:
no it's not allowing commas
FIATECHAuthor Commented:
I'm using 6.1 if that's a problem
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.