IsValid - CFMX 7

Updated , First Published by Pete Freitag

ColdFusion MX 7 added a new function called IsValid. The IsValid function performs data validation just like the CFPARAM tag, and supports all the new data types in cfparam (see my previous post) as well.

For instance if we want to validate the a variable has an integer value:

<cfif IsValid("integer", url.value)>
	Valid integer!
<cfelse>
	Invalid Integer!
</cfif>

For a range:

<cfif IsValid("range", url.value, 1, 100)>
	Value is between 1 and 100
<cfelse>
	Value is not between 1 and 100
</cfif>

And for regular expressions:

<cfif IsValid("regex", url.value, "[A-Z][a-z]+")>
	Word starts with a capital letter
<cfelse>
	Word does not match pattern.
</cfif>

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.

Comments

Raymond Camden

Hmm - according to the docs - the regex is a JS regex, not a CF regex. Anyone know why?

Pete Freitag

According to Ray's post on his blog, it does infact use CF Regex. http://ray.camdenfamily.com/index.cfm?mode=entry&entry=02586859-DBB8-5F75-494E8BC257561C56