开发者

Function to check if a variable name is valid

开发者 https://www.devze.com 2023-03-20 07:02 出处:网络
I have some code using the SetVariable function which takes the first parameter as a variable name created based on a variable name passed to this code.

I have some code using the SetVariable function which takes the first parameter as a variable name created based on a variable name passed to this code.

I'm looking for a way to check the string passed to it is a valid variable name using a function rather than using a try/catch block to trap this error.

I know there's a function IsValid but this only checks if the variable is valid, not if it's a valid variable name. Does anyone have any suggestions or custo开发者_运维问答m code they've used to do this?

Thanks,

Tom


I know there's a function IsValid but this only checks if the variable is valid, not if it's a valid variable name

Actually IsValid() will do what you want if you specify "variableName" as the type.

<cfoutput>#IsValid( "variableName","1")#</cfoutput>

Will output NO, since variable names in CF cannot begin with a digit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号