IsValid and RegEx Issues

While writing some new documentation on ColdFusion MX 7 features you may have missed (for the soon to be released Fusion Authority Quarterly Update), I came across an interesting issue with the IsValid function.

This function is used to test if a ColdFusion variable is of a particular data type or if it is a particular value (email address, credit card, etc). In many ways this is a single function that can stand in for most of the standard "IS" functions (IsStruct, IsQuery, etc.) One noted exception is that the function has no existance checking (IsDefined).

One feature of the function is the ability to use a regular expression as a validator. This makes the IsValid tag a perfect replacement for using REFind to do regular expression pattern validation. That is, with a single exception. REFind is case sensitive and has a NoCase version to deal with non-case sensitive matches. IsValid is only case sensitive.

For many, this may mean that using IsValid in place of REFind for regular expression pattern validation is not an option. To those I say, there is a simple solution.

ColdFusion MX 7 has some advanced options for regular expressions which include a simple prefix for any expression to make it case insensitive. To make IsValid in regular expression mode case insensitive, just do the following:

IsValid('regex', variable, '(?i)pattern')

The (?i) syntax at the start of a regular expression pattern makes the entire match case insensitive. Other advanced regular expression prefixes can be used with the function as well, which can greatly expand its capabilities.

Note that we are talking about the ColdFusion-style regular expressions here. The documentation for the IsValid function incorrectly states that it uses Javascript-style regular expression syntax. This is not the case.

There are a few other quirks with the function that you're almost never going to run into and I suggest you keep an eye on the IsValid LiveDocs entry for any changes and clarifications.

Comments
Ben Nadel's Gravatar I have not used the IsValid method very much yet, but I have to wonder about the benefits of using it over older, more specialized methods such as REFind() and IsStruct(). I can understand if the IsValid() function is much more powerful/efficient, but my gut reaction is that IsValid has to run some sort of switch statement on the type of expression being validated (regexp, SSN, phone, etc) and Then run the validation itself. Why not skip the type-checking and just call the actual checking method (ex. REFind())?

Again, I have not used it very much, so I am just giving stream-of-conscience here. I can understand that it can be great for people who might not know regexp for SSN matching and URL mathing, and that's really really cool... but is it really worth moving over to it for simple things like IsArray and IsStruct?
# Posted By Ben Nadel | 6/19/06 11:33 AM
Michael Dinowitz's Gravatar Logic says that there is some sort of switch inside that converts the text 'validation type' into a call to the proper type. This would mean that IsStruct and IsValid for structures are using the same code under the hood but the isValid has 'more' overhead. This would suggest that the more specialized versions are better.

I think the point of the function is as you said, to let people get string validation without having to write RegEx. Personally, I'd rather write some tight RegEx. :)
# Posted By Michael Dinowitz | 6/19/06 11:59 AM
abercrombie and fitch sale's Gravatar abercrombie and fitch sale uk
# Posted By abercrombie and fitch sale | 9/14/11 9:48 PM
burberry uk sale's Gravatar burberry outlet online
# Posted By burberry uk sale | 9/14/11 9:50 PM
moncler's Gravatar moncler jackets
# Posted By moncler | 9/14/11 9:50 PM
ralph lauren outlet's Gravatar franklin marshall outlet
Mens Franklin & Marshall
Franklin and Marshall Hoodie Sweatshirts
Ralph Lauren Hoodies
# Posted By ralph lauren outlet | 10/6/11 12:19 PM
The North Face Oulet's Gravatar The North Face Outlet offer Newest designer the north face jackets at a lowest price. Plus a huge selection of north face jacket, keeping latest style updating, free shipping all over the world.
# Posted By The North Face Oulet | 10/21/11 9:21 PM
moncler jackets's Gravatar So much so that you made me want to learn more about it. Your blog is my stepping stone, my friend. Thanks for the heads up on this subject.It has been

extremely informative as well as useful. This is totally awesome.
# Posted By moncler jackets | 11/16/11 2:58 AM
moncler jackets's Gravatar You had some nice points here. I done a research on the topic and got most peoples will agree with you
# Posted By moncler jackets | 12/12/11 3:04 AM
Office 2010's Gravatar in different folders for easy accessibility.
# Posted By Office 2010 | 12/13/11 3:39 AM
iwc replica's Gravatar The final step is included in the bill to increase taxes for all purchases, and the details of shipping and handling costs.
# Posted By iwc replica | 1/14/12 10:35 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner
House of Fusion | ColdFusion Jobs @ House of Fusion | Fusion Authority