# If- then - else in data editor

**URL:** <https://community.glideapps.com/t/if-then-else-in-data-editor/36269>\
**Category:** Ask for Help\
**Created:** [December 23, 2021, 6:35am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269 "2021-12-23T06:35:54Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Gabler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david_gabler/32/44332_2.png) [@David\_Gabler](https://community.glideapps.com/u/David_Gabler)\
**Post date:** [December 23, 2021, 6:35am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/1 "2021-12-23T06:35:54Z")

</div>

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…

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/a/daa5a0ea376fc85e4d8b9c459fcfddf133114573.png)

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/b/2b1baf46222a3ca9e6b6a16be860c033e064f75e.png)

Here’s the if then flow…

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/9/d91bd3cf9f1baabe3e5910d44b03f2dfd128f7fe.png)

explicitly stating “false” does not work either…

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/0/00486965c0e9705264283b748b79ab7d18a335a1.png)

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [December 23, 2021, 6:50am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/2 "2021-12-23T06:50:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![David\_Gabler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david_gabler/32/44332_2.png) [@David\_Gabler](https://community.glideapps.com/u/David_Gabler)\
**Post date:** [December 23, 2021, 7:02am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/3 "2021-12-23T07:02:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [December 23, 2021, 7:03am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/4 "2021-12-23T07:03:13Z")

</div>

> [@Himaladin](#):
>
> - If validName \>= 2 then true
> - If isPhone \>= 10 then true
> - if email is true then true
> - else false

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.

---

<div class="post-metadata">

**Author:** ![David\_Gabler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david_gabler/32/44332_2.png) [@David\_Gabler](https://community.glideapps.com/u/David_Gabler)\
**Post date:** [December 23, 2021, 9:45am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/5 "2021-12-23T09:45:06Z")

</div>

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)…

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/e/be2d5dbf23a81916bd599b0648afe6dd39c3c21f.png)

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [December 23, 2021, 3:53pm UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/6 "2021-12-23T15:53:49Z")

</div>

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:

> [@RegEx challenge (or just seems that way)](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/9):
>
> Hi again @Darren_Murphy and @Test_Test I get this using the JavaScript plugin, In my case, I only want phones with the format: XXXX-YYYYYYY (4 numbers \<5 + “-” + 7 numbers) const r = /([0-4]{4})-([0-9]{7}$)/; return r.test(p1) I hope it helps! Saludos.

Saludos!

---

<div class="post-metadata">

**Author:** ![David\_Gabler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david_gabler/32/44332_2.png) [@David\_Gabler](https://community.glideapps.com/u/David_Gabler)\
**Post date:** [December 23, 2021, 5:00pm UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/7 "2021-12-23T17:00:26Z")

</div>

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?)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/1/e145e9ccf66a36238816ff5c6f72850e25626ecd.png)

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [December 23, 2021, 6:23pm UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/8 "2021-12-23T18:23:09Z")

</div>

Hola de nuevo,

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

Saludos @David_Gabler

---

<div class="post-metadata">

**Author:** ![David\_Gabler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david_gabler/32/44332_2.png) [@David\_Gabler](https://community.glideapps.com/u/David_Gabler)\
**Post date:** [December 23, 2021, 6:27pm UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/9 "2021-12-23T18:27:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [December 23, 2021, 9:58pm UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/10 "2021-12-23T21:58:34Z")

</div>

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)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/a/8ab47ffd26874a392da32940788d6020fb1db1b3.png)

the JS code is:

```auto
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!

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [December 23, 2021, 10:07pm UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/11 "2021-12-23T22:07:48Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/0/d0866a70dc330c915d2fb09069cfc9fea6ed8b57.png)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [December 24, 2021, 12:04am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/12 "2021-12-24T00:04:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David\_Gabler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david_gabler/32/44332_2.png) [@David\_Gabler](https://community.glideapps.com/u/David_Gabler)\
**Post date:** [December 24, 2021, 12:34am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/13 "2021-12-24T00:34:21Z")

</div>

Thank you again!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [December 25, 2021, 12:35am UTC](https://community.glideapps.com/t/if-then-else-in-data-editor/36269/14 "2021-12-25T00:35:03Z")

</div>

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