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 syntaxIsValid(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> |
TYPE | |
VALUE | |
The value to test | |
MIN | |
MAX | |
PATTERN | |