How do I set up a condition that checks if the field is empty AND also a number?

Phil Schroeder shared this question 5 years ago
Answered

How do I set up a condition to both check if the field is empty (Count (Field X) = 0) and then also check to see if the field contains numbers? I know there is the "isNum" constant. But I can't figure out how to make it part of the same condition so it checks for both. I tried coping the entire interaction and just setting up a basic condition of (Field X = isNum) but that didn't work. Any suggestions would be helpful, thanks!

Comments (7)

photo
1

You have to build a condition like this:


First drag the '&' function to the expression.


Then drag an '=' function to the first parameter and a 'RegExp' function to the other parameter.


Then drag Field X to the first parameter of the '=' function and also the first in the 'RegExp' function.


Go to the Constants tab and drag the text one 'Aaa' to the second parameter of the '=' function. By default, that constant is an empty text.


Finally, drag the isNum constant to the second parameter of the RegExp function.


The result will look like this:


(Field X = ) & (RegExp(Field X, isNum)


If you want to know more about those functions check this section of the user's guide

photo
1

So this worked, except I had to add N outside all of the brackets since we're trying to generate an error if the field is not a number or if it's empty. Sorry probably didn't really make that clear. But still got the right end result, so thanks!

photo
1

Cool!

photo
1

Well now it's not working. Do you ever have users have issues with something working then when coming back into the prototype it no longer works? Obviously you could have forgotten to save it but otherwise ever had this issue? It seems to happen to me occasionally and I've gotten very ardent about saving. Anyways I'll send you the file, not sure why it doesn't work now.

photo
1

We don't usually have customers with that kind of problem. We do know sometimes people think they finished creating the expression but it was incomplete because instead of dragging elements to the expression they just select them (in the expression builder's outline view for instance) and press ok. Of course sending us the prototype will be really helpful to try to trace what's the problem.

photo
1

I've gotten well rounded enough at Justinmind that I came up with my own solution. It didn't like that I was putting together the empty field condition and the number condition. It was basically invalidating anything in there. So I separated it into to two separate interactions that I knew worked using the count field and the isNum expression. My two interactions looked like this...Interaction 1 - Count(Field X)=0, Interaction 2 - N(RegEx(Field X, isNum)). This worked like a charm. I've found in my experience that sometimes when I overcomplicate things it almost always works better if I just break something out into separate interactions. I shouldn't have to per se but I rather break it out and work then hit my head against a wall on why some complicated or weird condition isn't working. Thanks again!

photo
1

Wow Phil, good job! I always get amazed at how far users can get without training!