isValid

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

isValid(type, value, min, max, pattern) → returns boolean

Argument Reference for the isValid function

type

Required: Yes
The valid format for the data. Values:
  • Any
  • Array
  • Binary
  • boolean
  • creditcard
  • date
  • time
  • email
  • eurodate
  • float
  • Numeric
  • guid
  • integer
  • Query
  • range
  • Regex
  • regular_expression
  • ssn
  • social_security_number
  • String
  • Struct
  • telephone
  • URL
  • UUID
  • usdate
  • variablename
  • xml
  • zipcode
  • component

value

Required: Yes
The value to test.

min

Required: Yes
The minimum valid value; used only for range validation.

max

Required: Yes
The maximum valid value; used only for range validation.

pattern

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

Compatibility

ColdFusion:

Version 7+ CF 8+ - added component as a type option.
CF 11+ - no longer allows currency symbols at the start and commas inside a number. Can be reverted to legacy mode by setting this.strictNumberValidation = false in Application.cfc

Examples sample code invoking the isValid function


Check to see if a 235 is an integer

Use the isValid function with integer as the type.

isValid("integer", 235)

Expected Result: true


Validate an Email Address

Use the isValid function with email as the type.

isValid("email", "user@example.com")

Expected Result: true


Fork me on GitHub