If- then - else in data editor

I have the following configuration of users. In this case, if the name is not two words, or the email is not valid, or the phone number < 10 characters, I want to flag the account as “not approved”. However, it seems to be only checking for “valid name”, and ignoring the other conditions…

Changing the phone number to fewer than 10 characters, and it’s still flagged as “true” in approved.

Here’s the if then flow…

explicitly stating “false” does not work either…

The if function should not require filling the opposite condition.
How about you try this:

  • If validName >= 2 then true
  • If isPhone >= 10 then true
  • if email is true then true
  • else false

I haven’t tested it yet. I hope I’m not wrong.

1 Like

I actually got the same results with that which is why I tried testing both conditions… That is the first way I tried it.

Right idea, but I would flip the logic:

  • If validName < 2 then false
  • If isPhone < 10 then false
  • if email is not true then false
  • else true

An IF statement will always stop and return a result once it finds a satisfactory result. It will not continue and check all conditions unless it needs to. The IF logic in an IF column is essentially OR logic only.

7 Likes

Thank you. I marked it as a solution because it worked, but it showed a flaw in Glide’s ‘text length’ function. It gives a zero on my ‘word count’ function if there are no words, but ‘text length’ gives an ‘empty’ if the phone number is blank (to be consistent should give zero)…

Hola!

If I were you, I’d use a combination of JS code with RegEx syntax to save columns and time. All in one column.

Something like it here:

Saludos!

3 Likes

Hi gvalero, that is great! I’ve been wondering how to do that.
Now in my sample below you can see one phone number that is valid, except there are no -dashes-.
In most languages, there is a text mask that can be applied to what the user keys in to enter the dashes for them (after the fact – not during keyin). Is there a JS plugin to accomplish that so the second phone number is considered “valid”?

Also, is there a way to stay on the edit screen if they enter an invalid phone number (do not allow submit, or if they click submit, to send them back to the screen with all existing data intact after an alert?)

Hola de nuevo,

Let me try some tricks and come back with some idea.

Saludos @David_Gabler

1 Like

Thanks. Since posting, I have had the idea to just have two JS columns, and report true if either is true. But I have also noticed that the more computed columns you have, the slower Glide is, and sometimes makes the incorrect choice on screen visibility that is based on those columns.

1 Like

Hola @David_Gabler

I know it isn’t what you want exactly but can be useful:

Here you can allow that any user writes a dash (-) or 2 dashes or none along to the phone number and get a True as result (as validation)

the JS code is:

const r = /^([0-5]{3})?-?([0-9]{3})?-?([0-9]{4})$/;

return r.test(p1); 

Also, is there a way to stay on the edit screen if they enter an invalid phone number (do not allow submit, or if they click submit, to send them back to the screen with all existing data intact after an alert?)

I’d use a Submit button ruled by a visibility condition to show/hide it if the phone format is right (RegEx JS column)

Saludos David!

3 Likes

Also @David_Gabler, you can use Check Text Matches plugin to do this operation directly and have a better view: :wink:

2 Likes

Just commenting to say your regexes are wonderful. Thanks for sharing the knowledge.

3 Likes

Thank you again!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.