The validation tool found in the Mi-Forms designer is quite robust and can be used in a host of different validation types, but sometimes a form requires some special validation that is not available as a part of the typical rule set. This becomes particularly important when developing for iOS and Android devices. These devices do not use a pen for input, so Constrained Text (CText) is not easily enforced. But that does not mean you can't customize these validations. You can, and it is actually quite simple as in the following example:


There is the Form.handleRule Method 

function handleRule(ID, satisfied, critical, shortDescription, longDescription, highlight, highlightColor, fieldList);

 

You can use it in the MFValidate region of your Javascript. Basing off of this example:

   

var bRes;
bRes = (/^#(([a-fA-F0-9]{3}$)|([a-fA-F0-9]{6}$))/.test(_form.getValue("hexValue")));
_Form.handleRule('VR1', bRes, true, "Hex Value is incorrect.", "Enter a correct Hex Value.", true, "rgba(255,255,0, 0.5)", ['hexValue']);

   


where bRes must be declared only once for any number of custom validations. Line 2 sets bRes to true if the field 'FirstName' is empty. Line 3 uses the handleRule function to look for bRes = true, then sets validation rules (FirstName is required.), sets the field to highlight - yellow - and declares ['FirstName'] as the field to affect (can be more than 1 field by inlcuding more fields within the bracket). This can be changed to highlight a field if it contains characters other than what you would like by changing the bRes = line. It can also be used to create any kind of custom validation rule.


This is very basic, and the only validation is ensuring that there is an entry in the "FirstName" field of the form. However, you can change the boolean to be as complicated as you need. The following example checks to make sure a valid hexadecimal color code is entered:


  

var bRes;
	bRes = (/^#(([a-fA-F0-9]{3}$)|([a-fA-F0-9]{6}$))/.test(_form.getValue("hexValue")));
	_Form.handleRule('VR1', bRes, true, "Hex Value is incorrect.", "Enter a correct Hex Value.", true, "rgba(255,255,0, 0.5)", ['hexValue']);