Description

Tests whether a value meets a validation or data type rule.

Returns

True, if the value conforms to the rule; False, otherwise.

Category

Decision functions

Function syntax

IsValid(type, value) 
isValid("range", value, min, max) 
isValid("regex" or "regular_expression", value, pattern)

See also

cfparamcfformIsBooleanIsDateIsNumericIsSimpleValueValidating data with the IsValid function and the cfparam tag in the Developing ColdFusion Applications

History

ColdFusion (2016 release) Update 3: Added datetime_object as type.

ColdFusion 11: Behavioral change

Prior to ColdFusion 11,  this function allowed currency symbols at the start and commas inside the number. Starting from ColdFusion 11, this function evaluates on a more strict basis. To revert to the old behavior use the application-level setting STRICTNUMBERVALIDATION to false. 

ColdFusion 8: Added the component value for to the type parameter.

ColdFusion MX 7: Added this function.

Parameters

Parameter

Description

type

The valid format for the data; one of the following. For detailed information on validation algorithms, see Validating form data using hidden fields in the Developing ColdFusion Applications.

  • array: a ColdFusion array; equivalent to the IsArray function.
  • binary: a binary value;; equivalent to the IsBinary function.
  • boolean: a Boolean value: yes, no, true, false, or a number; equivalent to the IsBoolean function.
  • component: a ColdFusion component (CFC).
  • creditcard: a 13-16 digit number conforming to the mod10 algorithm.
  • date or time: any date-time value, including dates or times; equivalent to the IsNumericDate function.
  • datetime_object: any valid ColdFusion date/time object.
  • email: a valid email address. You can also pass IPV6 format values.
  • eurodate: any date-time value, including US date formats and time values,
  • numeric: a numeric value; equivalent to the IsNumeric function.
  • guid: a Universally Unique Identifier of the form "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" where X is a hexadecimal number.
  • integer: an integer.
  • query: a query object; equivalent to the IsQuery function.
  • range: a numeric range, specified by the min and max parameters.
  • regex or regular_expression: matches input against pattern parameter.
  • ssn or social_security_number: A U.S. social security number.
  • string: a string value, including single characters and numbers
  • struct: a structure; equivalent to the IsStruct function.
  • telephone: a standard US telephone number.
  • URL: an http, https, ftp, file, mailto, or news URL. You can also pass IPV6 format values.
  • UUID: a ColdFusion Universally Unique Identifier, formatted XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXX, where X is a hexadecimal number. See CreateUUID.
  • USdate: a U.S. date of the format mm/dd/yy, with 1-2 digit days and months, 1-4 digit years.
  • variableName: a string formatted according to ColdFusion variable naming conventions.
  • zipcode: U.S., 5- or 9-digit format ZIP codes.

value

The value to test

min

The minimum valid value; used only for range validation

max

The maximum valid value; used only for range validation

pattern

A JavaScript regular expression that the parameter must match; used only for regex or regular_expression validation.

Usage

The IsValid function lets you assure that validation is performed on the server. You can use the cfparam tag to perform equivalent validation.

Example

The following example checks whether a user has submitted a numeric ID and a valid e-mail address and phone number. If any of the submitted values does not meet the validation test, it displays an error message.

<cfif isDefined("form.saveSubmit")> 
<cfif isValid("integer", form.UserID) and isValid("email", form.emailAddr) 
and isValid("telephone", form.phoneNo)> 
<cfoutput> 
<!--- Application code to update the database goes here ---> 
<h3>The email address and phone number for user #Form.UserID# 
have been added</h3> 
</cfoutput> 
<cfelse> 
<H3>You must supply a valid User ID, phone number, and email address.</H2> 
</cfif> 
<cfelse> 
</cfif> 

<cfform action="#CGI.SCRIPT_NAME#"> 
User ID:<cfinput type="Text" name="UserID"><br> 
Phone: <cfinput type="Text" name="phoneNo"><br> 
email: <cfinput type="Text" name="emailAddr"><br> 
<cfinput type="submit" name="saveSubmit" value="Save Data"><br> 
</cfform>

In ColdFusion 11, the isValid function behaves in a different way. Setting strictnumbervalidation to false makes the isValid function to behave in a way just like in the previous versions (ColdFusion 10 or earlier). Starting from ColdFusion 11, a more strict approach will be followed for validation. However,  if you need the isValid function behavior to be of ColdFusion 10, set the key/tag attribute strictnumbervalidation to false in application cfc/cfm.

Application.cfm

 

<cfapplication name="hello" STRICTNUMBERVALIDATION="false" >

Application.cfc

<cfcomponent>
<cfscript>
{
this.STRICTNUMBERVALIDATION = false;
}
</cfscript>
</cfcomponent>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy