2013-05-31 39 views
1
<td><input type="text" MAXLENGTH="5" <cfif isdefined ("saverecord1") and isdefined("form.startnum") and form.startnum neq ''>value="#form.startnum#" <cfelse>value=""</cfif> onkeyup="toupper(this)" name="startnum" id="startnum"></td> 

<td><input MAXLENGTH="5"type="text" <cfif isdefined ("saverecord1") and isdefined("form.endnum") and form.endnum neq ''>value="#form.endnum#" <cfelse>value=""</cfif> onkeyup="toupper(this)" name="endnum" id="endnum"></td> 

<cfset x = #REFind('[^a-z]', '#form.startnum#')# >      

<cfset x = "#form.startnum#"> 
<cfif Len(Trim(x)) GT 0> 
    <cfset x = RemoveChars(x,1,1)> 
</cfif> 

<cfset y = "#form.ENDNUM#"> 

<cfif Len(Trim(y)) GT 0> 
    <cfset y = RemoveChars(y,1,1)> 
</cfif>  
<cfif y gt x>    
    <cfset total = y - x> 
<cfelse> 
    <script> 
    alert('Starting key number has to be greater than the ending key number! Please enter again'); 
    </script> 
</cfif> 

我有2个文本框,在其中用户可以输入像M1000字母数字键的数字也数字键号码,如1000,我能处理字母数字键码,同时产生自动增量键码。如何检查是否一个字符串的ColdFusion有一个角色在它

但是,对于数字键条目1000像上述失败,因为我删除不存在的字符和条目不被接受。如果refind()是我可以用来查找我的字符串条目中是否有任何字符的函数,请指教。谢谢

+0

你在纯英语中的目标是什么?确保'form.startNum'的数字部分,即'1000'不超过'form.endNum'?与您的问题无关,但不需要任何'#'标志,除了''标签内的标志外。另外,你可以通过用'cfparam'设置默认的'form'值来简化代码,然后移除'isDefined'语句。 – Leigh

回答

1

ReFind是一个合适的函数,但是在使用它之前,您正在覆盖变量x。在这里你给x赋值。

<cfset x = #REFind('[^a-z]', '#form.startnum#')# > 

然后再指定值X

<cfset x = "#form.startnum#"> 

然后使用该变量:

<cfif Len(Trim(x)) GT 0> 

这CFIF相同

<cfif Len(Trim(form.startnum)) GT 0> 

但你可能想要这个:

<cfif REFind('[^a-z]', '#form.startnum#') GT 0> 
+0

Form.startnum是可以接受的。你不需要“或者# –

相关问题