Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfform validatation question

Status
Not open for further replies.

jwdcfdeveloper

Programmer
Mar 20, 2001
170
0
0
US
Does anyone know if the integer validation of a cfinput text box can be triggered by white spaces? I ask because I am modifying a page and when I was ready to submit the page, I get stopped by the integer validation, informing me to enter whole monitary amounts only. All of my fields are populated from a database and are either blank, or have whole numbers in them. So the only thing I can think of is whitespaces. If that's the case do the Trim, LTrim, RTrim, etc. functions work for numbers too? If not does anyone either know of a function that removes whitespaces, or know what else could be causing the error message to trigger.
 
We ran into a similar problem with stored procedures when we moved from a CF5 to a CFMX server. We ended up using only cfsqltype="CF_SQL_VARCHAR" for type="In" because using cfsqltype="CF_SQL_NUMERIC" caused a numeric error when passing data type of "" (null). I just ran some tests on your problem and got the same results.

Here is some code to play with.

<!--- Save this section as input_page.cfm --->
<cfparam name=&quot;int_test1&quot; default = &quot;&quot;>
<cfparam name=&quot;int_test2&quot; default = &quot;&quot;>

<table class=&quot;report&quot; cellspacing=&quot;1&quot; width=&quot;200&quot; border=&quot;1&quot;>
<cfform name=&quot;test&quot; action=&quot;input_page.cfm&quot; method=&quot;POST&quot;>
<tr>
<td nowrap>My Number with input validation.</td>
<td>
<!--- Putting trim() around int_test here only trims when the page loads. It does not
trim the value when the page performs any checks upon submitting. --->
<cfinput type=&quot;Text&quot; name=&quot;int_test1&quot; value=&quot;#trim(int_test1)#&quot; validate=&quot;integer&quot;
message=&quot;Please enter an integer&quot;>
</td>
<td colspan=&quot;2&quot; align=&quot;center&quot;>
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</td>
</tr>
</cfform>
</table>

<table class=&quot;report&quot; cellspacing=&quot;1&quot; width=&quot;200&quot; border=&quot;1&quot;>
<cfform name=&quot;test2&quot; action=&quot;validation_page.cfm&quot; method=&quot;POST&quot;>
<tr>
<td nowrap>My Number validated on a second page</td>
<td>
<!--- Putting trim() around int_test here only trims when the page loads. It does not
trim the value when the page preforms any checks upon submitting. --->
<cfinput type=&quot;Text&quot; name=&quot;int_test2&quot; value=&quot;#int_test2#&quot; >
</td>
<td colspan=&quot;2&quot; align=&quot;center&quot;>
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</td>
</tr>
</cfform>
</table>

<!--- Second page - save this section as validation_page.cfm -
if you do your validation here, you can catch the spaces --->

<!--- remove any leading or trailing blank spaces --->
<cfset int_test2 = trim(int_test2)>

<!--- attempt to get CF to put variable back in &quot;stateless mode&quot; --->
<cfset int_test3=int_test2>

<cfif isNumeric(int_test3)>
<!--- Uncomment the following line to filter out blank spaces --->
<!--- <cfif isNumeric(int_test3) or int_test3 is &quot;&quot;> --->

<cfoutput>#int_test3# is a valid number!</cfoutput>

<cfelse>

<cfoutput>Check for blanks ***#int_test3#***</cfoutput>
<script language=&quot;JavaScript&quot;>
<!--
window.alert(&quot;Please enter a valid number&quot;);
window.history.go(-1);
//-->
</script>
<cfabort>

</cfif><!--- isNumeric(int_test) or int_test is &quot;&quot; --->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top