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 custom code they've used to do this?
Thanks,
Tom
A valid variable name begins with a letter and contains not more than namelengthmax characters. Valid variable names can include letters, digits, and underscores.
Variable name may not start with a digit or underscore, and may not end with an underscore. Double underscores are not permitted in variable name. Variable names may not be longer than 32 characters and are required to be shorter for some question types: multiselect, GPS location and some other question types.
A valid variable name starts with a letter, followed by letters, digits, or underscores.
A valid variable name consists of a combination of alphabets, numbers, dot(.), and underscore(_) characters. Example: var. 1_ is valid. Apart from the dot and underscore operators, no other special character is allowed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With