The Robertson Team


  Programmers' Tools >  The Free Stuff >  GridMonger >  FAQ >  How do I use the server-side form field validation feature?

How do I use the server-side form field validation feature?

Short answer:  Learn how to use regular expressions.  Ben Forta's new book on the subject is the best quick-read you can find.

Not quite as short of an answer: While it won't teach you regular expressions, registered GridBuilder users don't have to build the field validation arrays by hand, as GridBuilder does this for you.

GridMonger allows you to store a regular expression -- and a friendly error message to display -- for each of your grid's data fields.  The Field Validation Area of your grid config file (see the documented /embeddeddemo.cfm grid config file found in your GridMonger file set) contains a two-dimensional array that holds this information.

Enter nil in both elements to specify no validation. (do NOT get the bright idea of adding a regular expression to a noneditable field.  This will cause edits to be ignored).  The regular expression should be exactly the string you would put into a ColdFusion REFIND() statement, so if you want case INsensitivity, build it into your regular expression. For example, this array item entry

request.FieldValidator[1][2]="Idiot! You must use a valid email address format."

would be used just as it would be in this ordinary block of code:

<CFSET EmailAddress = "">
     <CFIF REFind("^[’_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|([A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.(([A-Za-z]{2,3})|(aero|coop|info|museum|name)))$",EmailAddress)>
     #EmailAddress# appears to be valid
     You submitted #EmailAddress#<br>

NOTE: Only /inlinedemo.cfm has field validation enabled (on the city name field).  For demonstration purposes, the regular expression placed there will deliberately fail on some of the sample data in this table. Any city with a space in its name (for example, ST THOMAS) will cause a failure.

The Robertson Team,
1.559.360.1717 is a leader in ColdFusion web hosting and managed dedicated servers.