# Extract Last four digits from a phone no

**URL:** <https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030>\
**Category:** Ask for Help\
**Created:** [November 19, 2024, 7:57pm UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030 "2024-11-19T19:57:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben164](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ben164/32/54019_2.png) [@Ben164](https://community.glideapps.com/u/Ben164)\
**Post date:** [November 19, 2024, 7:57pm UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/1 "2024-11-19T19:57:02Z")

</div>

Good evening,

Hope you are well.

I am looking for some help removing the ‘0.’ from the screenshot please. So it leaves me with just a plain 4 digit number each time. I have tried splitting the text but cannot get it to work as planned. I also tried using the Row ID to generate a random no too, but couldn’t get the result I was looking for.

Perhaps there is a better way for Glide to produce me a random 4 digit code without using precision to 4 decimal places to give me the code in the random no column? Any ideas please?

Thanks in advance.

 ![Screenshot 2024-11-19 at 19.51.41](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/b/6b0148c7784fd4a5d088297d531f2db4d2f12bc8.png)

 ![Screenshot 2024-11-19 at 19.57.27](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/8/987dd4de535d3f8f79ab4d7ceadd7e4d7d8f0c8f.png)

---

<div class="post-metadata">

**Author:** ![Hassan\_Nadeem](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/hassan_nadeem/32/72956_2.png) [@Hassan\_Nadeem](https://community.glideapps.com/u/Hassan_Nadeem)\
**Post date:** [November 19, 2024, 8:59pm UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/2 "2024-11-19T20:59:58Z")

</div>

Employee ID needs to be the last 4 digits of their phone number?

or does it need to be random and unique 4 digit number for each employee?

---

<div class="post-metadata">

**Author:** ![Ben164](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ben164/32/54019_2.png) [@Ben164](https://community.glideapps.com/u/Ben164)\
**Post date:** [November 19, 2024, 9:14pm UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/3 "2024-11-19T21:14:18Z")

</div>

Either option works, as long as it’s a unique four digits. The latter is preferable please.

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [November 19, 2024, 10:50pm UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/4 "2024-11-19T22:50:17Z")

</div>

You could use the text slice column to get the last 4 of the phone number or a roll dice column with 9999 sides.

Keep in mind there’s only 9999 possible numbers if you take either approach

Alternatively you could use a little bit of JS. Something like this I found from Jeff would work and would be more robust.

`return Math.floor(Math.random() * 1e12).toString().padStart(12, '0');`

Add a unique value to p1

---

<div class="post-metadata">

**Author:** ![Hassan\_Nadeem](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/hassan_nadeem/32/72956_2.png) [@Hassan\_Nadeem](https://community.glideapps.com/u/Hassan_Nadeem)\
**Post date:** [November 19, 2024, 10:57pm UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/5 "2024-11-19T22:57:17Z")

</div>

If I am not wrong, roll dice column can’t guarantee unique IDs for each employee correct? @Eric_Penn

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [November 19, 2024, 11:00pm UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/6 "2024-11-19T23:00:32Z")

</div>

Roll dice is not good for unique codes… but neither is using 4 digits or last 4 of phone number 🤷‍♂️

I’d go with some JS

---

<div class="post-metadata">

**Author:** ![Ben164](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ben164/32/54019_2.png) [@Ben164](https://community.glideapps.com/u/Ben164)\
**Post date:** [November 20, 2024, 8:15am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/7 "2024-11-20T08:15:04Z")

</div>

Thanks all for the feedback. If you were to generate a four or six digit random code how would you go about doing this then? It sounds like the general feedback is that doing it the way I proposed is not ideal? Happy for any better approaches, or is JS the most sensible option here?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [November 20, 2024, 8:19am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/8 "2024-11-20T08:19:15Z")

</div>

Generating a random 4 or 6 digit code is trivial - there are umpteen different ways that can be done.

The critical question is - does it need to be unique?

If it does, then you are limited to 9999 and 999999 codes respectively, and it gets somewhat more complicated, because you need to keep track of the codes that have been assigned.

---

<div class="post-metadata">

**Author:** ![Ben164](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ben164/32/54019_2.png) [@Ben164](https://community.glideapps.com/u/Ben164)\
**Post date:** [November 20, 2024, 8:48am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/9 "2024-11-20T08:48:32Z")

</div>

I suppose it would have to be unique and with only 30 odd employees this will be fine. Staff will clock in and out on a Glide screen on a clock in/out module, but the system needs to know which 4 or 6 digit code relates to which employee when they clock in/out.

If it is easier, I can simply generate a four digit random code myself.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [November 20, 2024, 8:52am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/10 "2024-11-20T08:52:25Z")

</div>

What is the actual purpose of the code?  
I assume that your Staff will sign into the App?  
If they are signed in, then you have already identified who they are and there should be no reason to use any codes 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Ben164](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ben164/32/54019_2.png) [@Ben164](https://community.glideapps.com/u/Ben164)\
**Post date:** [November 20, 2024, 9:05am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/11 "2024-11-20T09:05:03Z")

</div>

They will not be signed into the app, they will get to work and click on an open glide screen (open to all) with the 4 or 6 code to register their clock in or out. The owner doesn’t want everyone to sign into glide individually or out of glide (I know, obvious solution!).

They would like a simple code to follow their existing operations flow. Hopefully this is enough background.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [November 20, 2024, 9:16am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/12 "2024-11-20T09:16:57Z")

</div>

Okay, I see.

If it’s just 30 odd users, I would be inclined to just manually allocate the codes.

You should be aware though that this is not a very secure solution. The full list of codes and associated user mappings will be loaded onto every user device, and discoverable by anyone with sufficient skills and motivation - including anyone in the world that happens to learn the App URL.

---

<div class="post-metadata">

**Author:** ![Ben164](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ben164/32/54019_2.png) [@Ben164](https://community.glideapps.com/u/Ben164)\
**Post date:** [November 20, 2024, 9:30am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/13 "2024-11-20T09:30:20Z")

</div>

Thank you for this. Yes all noted. I appreciate the security concerns and have flagged this already - it would not have been my preferred approach!

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [November 20, 2024, 11:20am UTC](https://community.glideapps.com/t/extract-last-four-digits-from-a-phone-no/78030/14 "2024-11-20T11:20:28Z")

</div>

What if you stored the encrypted codes using sha-256… then when the user is inputting his code run that through sha-256 and compare

Maybe overkill or might be worth looking into
