When using a field as a Boolean switch, it's desirable to limit the potential for bad data entry - or your own bad coding! This is similar to using a validation on a phone number field, where strict requirements must be met. Because the validation is strictly enforced, this will increase your level of confidence with regards to the contents of Boolean fields.


The following guidelines are suggested for Boolean fields.

This best practice assumes you're not attempting to HIGHLY OPTIMIZE your data storage and you're Ok with storing a zero (0) for a false value. If you're using a 1/Null setup, then you'll need to adjust the validation calculation accordingly

Image #1

Image #2

Image #3

There are a number of ways to switch a 1 to a 0 and a 0 to a 1. The most efficient is to use the xor operator. Here's an example:

$isStudent xor 1

or to use the standards specified on this site, the more readable is this

$isStudent xor True