ISVALID  
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

cfparam, cfform, IsBoolean, IsDate, IsNumeric, IsSimpleValue; "Validating data with the IsValid function and the cfparam tag" in Chapter 28, "Validating Data," in ColdFusion MX Developer's Guide

 
History

ColdFusion MX 7: Added this function.

 
Parameters

 
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 email 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>

The valid format for the data; one of the following. For detailed information on validation algorithms, see "Validating form data using hidden fields" in Chapter 28, "Validating Data," in ColdFusion MX Developer's Guide.

TYPE  
VALUE  
  The value to test
 

The minimum valid value; used only for range validation

MIN  

The maximum valid value; used only for range validation

MAX  

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

PATTERN