Tests whether a value meets a validation or data type rule.
True, if the value conforms to the rule; False, otherwise.
IsValid(type
,value
) isValid("range
",value
,min
,max
) isValid("regex
" or "regular_expression
",value
,pattern
)
cfparam, cfform, IsBoolean, IsDate, IsNumeric, IsSimpleValue; "Validating data with the IsValid function and the cfparam tag" in the ColdFusion Developer's Guide
ColdFusion 8: Added the component value for to the type attribute.
ColdFusion MX 7: Added this function.
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 ColdFusion Developer's Guide.
|
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. |
The IsValid function lets you assure that validation is performed on the server. You can use the cfparam tag to perform equivalent validation.
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>