missbrad
Scholar

Custom Validation on SLT Form Field

I have been successful in using custom validation to validate an SSN field or EIN field using the custom validation built into the field control settings ([0-9]{3}-[0-9]{2}-[0-9]{4} or [0-9]{2}-[0-9]{7}) however I have one SLT field that will hold the response for an EIN which may be an SSN OR EIN based on a choice field (Entity Type, choices are "Individual" and "Business").

Based on the choice in the Entity Type field i would like to set the custom validation so that the EIN entered is the appropriate pattern. 

How do I write the Custom Validation Formula if it depends on the value in another field?

I have tried several combinations but cannot get the validation to work - the one that made the most sense was:

fn-IfElse(Entity Type == "Individual"), [0-9]{3}-[0-9]{2}-[0-9]{4}, [0-9]{2}-[0-9]{7}

The field cannot be blank and is already mandatory

0 Kudos
Reply
3 Replies
Tarf
Explorer

Re: Custom Validation on SLT Form Field

Hi,

you have a misplaced bracket in your formula:
fn-IfElse(Entity Type == "Individual"), [0-9]{3}-[0-9]{2}-[0-9]{4}, [0-9]{2}-[0-9]{7} should be
fn-IfElse(Entity Type == "Individual",[0-9]{3}-[0-9]{2}-[0-9]{4}, [0-9]{2}-[0-9]{7})

Do you take the Entity Type from the Item Properties? Form controls do not show for me when trying to use the custom validation.

I´d suggest switching to form rules for validation. I personally find them easier to work with.
A rule suited for your needs would be

EntityType === "Individual" && replace({Self},"[0-9]{3}-[0-9]{2} ...","") == ""

 This would replace your regular expression from the control and check if it is empty afterwards, if the EntityType is Individual. For you other case, you´d create another rule.

 

0 Kudos
Reply
missbrad
Scholar

Re: Custom Validation on SLT Form Field

Thanks! I tried both and neither one actually gave me a validation error ( or a bad formula error). I should have mentioned that this field is in a repeating section. That's why I was trying to use the control settings. When I set it up from control settings I do only have the option for item properties like you mentioned, however it is a named control.

Does this make a difference?

0 Kudos
Reply
Tarf
Explorer

Re: Custom Validation on SLT Form Field

Hi @missbrad,

rules can also be applied to controls in a repeating section. So this shouldn´t be a problem.

Named Controls and Item Properties differ in when their values are changed.
Item Properties are loaded when the form loads and saved when you save.
Named controls update in real time when values are changed in your form.

0 Kudos
Reply