LiveCode for FM ManualValidation and CheckingHow do I validate the contents of a field?

How do I validate the contents of a field?

Field Validation

When users enter text into database fields it often needs to be in a certain form to be valid. FileMaker allows you to specify a calculation to validate a field. Here we have created a text field named `Value`.

Our value is going to be valid if if there are three numbers separated by hyphens and the first number is 123, the second is an even number and the third is an odd number. For example the values 123-456-789 and 123-1000-1 are valid and the values 123-456-780 and 124-456-789 are invalid.

Once you have created the field click the `Options...` button indicated in the screenshot with a 1 marker.

Validation Calculation

Go to the Validation tab and check the `Validated by calculation` checkbox. Now click `Specify...` to enter a calculation to validate the field.

Using LCExec

Any newlines entered into the FileMaker `Specify Calculation` dialog are removed so when using LCEval here we need to use LiveCode's newline synonym `;` for each command. Any quotes in the script need to be escaped with FileMaker's escape character `\`

Enter the validation script into the `Specify Calculation` dialog as follows and click OK.

LCExec ( "
   local tValue;
   put fmParam(1) into tValue;
   set the itemDelimiter to \"-\";
   return the number of items of tValue is 3 and 
      item 2 of tValue is an integer and 
      item 2 of tValue mod 2 is 0 and 
      item 3 of tValue is an integer and 
      item 3 of tValue mod 2 is 1"
; Value )
Click to copy

Invalid Entry Message

Entering a custom invalid entry message is a good idea to ensure users don't become frustrated if they don't know the form of a valid entry. On the `Validation` tab of the `Field Options` dialog check the `Display custom message if validation fails` checkbox and enter a message describing the required form of a valid entry.

Testing Validation

Test the field validation with valid and invalid entries to ensure the validation failure dialog is presented appropriately.


Mark Waddingham

Perhaps this should be 'How do I validate the contents of a field?'

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.