AnsweredAssumed Answered

Validation calculation for one of two input values

Question asked by m.swanston on Mar 15, 2016
Latest reply on Mar 15, 2016 by m.swanston

So following on from a previous question, I have an input that I'd like to validate with a calculation, but have been told that users can enter the value in one of two different formats:

NN.NN or NN.NN.NN, ie 01.04 or 01.04.01

I took some validation from another field I'd had some help with and extended it, but it's not working (and I understand why, just not sure how best to write it to work for how I need).

Currently, the calculation (which is not enabled) is set to list the logic I need:

Case (
  Length ( Self ) ≠ 5; 0;
  Length ( Self ) ≠ 8; 0;
  Middle ( Self; 3; 1 ) ≠ "."; 0;
  Middle ( Self; 6; 1 ) ≠ "."; 0;
  Length ( Filter ( Left ( Self; 2 ); "0123456789" ) ) ≠ 2; 0;
  Length ( Filter ( Middle ( Self; 4; 2 ); "0123456789" ) ) ≠ 2; 0;
  Length ( Filter ( Right ( Self; 2 ); "0123456789" ) ) ≠ 2; 0;
  1
)

But, in my head, what I need to do is to validate for either scenario, something like:

If Length( Self ) = 5;
Case (
  Middle ( Self; 3; 1 ) ≠ "."; 0;
  Length ( Filter ( Left ( Self; 2 ); "0123456789" ) ) ≠ 2; 0;
  Length ( Filter ( Right ( Self; 2 ); "0123456789" ) ) ≠ 2; 0;
  1
);
If Length( Self ) = 8;
Case (
Middle ( Self; 3; 1 ) ≠ "."; 0;
  Middle ( Self; 6; 1 ) ≠ "."; 0;
  Length ( Filter ( Left ( Self; 2 ); "0123456789" ) ) ≠ 2; 0;
  Length ( Filter ( Middle ( Self; 4; 2 ); "0123456789" ) ) ≠ 2; 0;
  Length ( Filter ( Right ( Self; 2 ); "0123456789" ) ) ≠ 2; 0;
  1
)))

Whilst I could try it out, I just want to be sure that it's the best way to code it, am not sure the nested If is a good method, but be good to get some feedback on how to code this in the neatest syntax.

Many thanks

Martin

Outcomes