# RegEx challenge (or just seems that way)

**URL:** <https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138>\
**Category:** Ask for Help\
**Created:** [December 20, 2021, 1:48pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138 "2021-12-20T13:48:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Test\_Test](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/test_test/32/30930_2.png) [@Test\_Test](https://community.glideapps.com/u/Test_Test)\
**Post date:** [December 20, 2021, 1:48pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/1 "2021-12-20T13:48:11Z")

</div>

Hi all,  
I’m having one of these blank/blocked moments.  
In a nutshell, trying to validate entry for phone number. I’m building a customs form, as shown by @Darren_Murphy’s [great example](https://community.glideapps.com/t/how-do-i-create-a-custom-form/25014).  
I’ve chosen the “Phone Entry” field. This field should accept, well you guessed it, just digit/numbers. It’s true that in some rather rare situations you do want to add letter or other characters, but I assume you’ll agree the default should be limited to just digits. The “Phone Entry” field is **NOT** limited to digits only, nor is it configurable in any way. Any ideas on how to validate that the input is just digits?  
Wait, now comes the challenge:  
Of course I’m using RegEx and it’s working flawlessly. However, it’s “firing” too early, such as:

1. RegEx is supposed to limit the first two characters to just “05”. For this reason, I’ve added a column to count the characters and the alerts only fires from the third characters onwards. This is to prevent the alert coming up within the first character input (even if that character is indeed “0” as it should be). The rest of the RegEx indeed limits to just digits and at a certain length.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/9/0987be0ebb69a0f938369ead998c1ee07e76a9b5.png)

2. I added another column with a math formula of “phone number”/“phone number”. It fires an alert if it’s equal to “” (left blank. For some reason it’s not working with entering “1”). However, the first character is 0 and 0/0 doesn’t equal 1.0… ☹ This causes the alert to fire when you enter the first (correct) character (“0”).  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/6/1644cf53a386691786d3fa1ab7f5984b8bb3c8ed.png)

Any ideas?  
I’m almost certain this is a very basic issue that I’m missing, but that’s how “writer’s block” work…

---

<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 20, 2021, 2:29pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/2 "2021-12-20T14:29:59Z")

</div>

In my opinion, the phone entry accepts text as well because we can have cases where there are letters in the number, albeit in my understanding it might be an old-school way.

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

Back to your question, do you want to validate the input should only be digits and the first two characters are “05”?

---

<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:** [December 20, 2021, 2:46pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/3 "2021-12-20T14:46:19Z")

</div>

> [@Test\_Test](#):
>
> but I assume you’ll agree the default should be limited to just digits.

Nope. In my world (and in my contact list), any phone number that doesn’t start with `+` is an invalid number 😛

Validating phone numbers with regex is a bit of a slippery slope. Every time you think you’ve nailed it, you’ll find another edge case that breaks it. And before you know it you’ll have something that looks like this:

```auto
/^
 \+ [[:space:]]* [0-9] [0-9.[:space:]-]*
 ( \( [0-9.[:space:]-]* [0-9] [0-9.[:space:]-]* \) )?
 ( [0-9.[:space:]-]* [0-9] [0-9.[:space:]-]* )?
 ( [[:space:]]+ 
   ext . 
      [0-9.[:space:]-]* [0-9] [0-9.[:space:]-]* 
 )?
$/xi

```

If you really want to do it, then you’re probably better off using an existing [library](https://www.skypack.dev/search?q=phone&p=1).

> [@How to import code packages in the JavaScript column](https://community.glideapps.com/t/how-to-import-code-packages-in-the-javascript-column/34466):
>
> The [JavaScript column](https://www.glideapps.com/plugins/hell-yes-code) already includes [lodash](https://lodash.com/), which provides a value named \_ with many useful utility functions. lodash is the most popular JavaScript library in the world, so we included it by default even if you do not use it. @Jeff_Hager recently [requested](https://github.com/glideapps/glide-code-columns/issues/82) mathjs support in the JavaScript column. mathjs is another top JavaScript library, but including it by default means that every app that uses the JavaScript column would load this library as well, even though very few people need it. Tod…

---

<div class="post-metadata">

**Author:** ![Test\_Test](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/test_test/32/30930_2.png) [@Test\_Test](https://community.glideapps.com/u/Test_Test)\
**Post date:** [December 20, 2021, 3:36pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/4 "2021-12-20T15:36:01Z")

</div>

You’re absolutely right and that’s why our RegEx doesn’t really check the phone number, rather its VERY general syntax. Far for failproof, but good enough for now.  
I couldn’t find a tutorial for these JS columns. Is there one?

---

<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:** [December 20, 2021, 3:39pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/5 "2021-12-20T15:39:03Z")

</div>

I don’t think so. That post of David’s that I linked to is about as close as we have, I think.

Oh, it might be worth checking some of @gvalero’s posts. He’s done quite a bit with it.

---

<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:** [December 20, 2021, 4:29pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/6 "2021-12-20T16:29:06Z")

</div>

Hey @Darren_Murphy I’m looking for a way to validate a text entry when it has a a minimum of 4 characters. (Case insensitive and not including spaces)

I came across this RegEx…

```auto
[A-Za-z][^A-Za-z]*[A-Za-z][^A-Za-z]*[A-Za-z][^A-Za-z]*[A-Za-z]

```

I guess my question to you is does this look right? Through my preliminary testing it did seem to work.

---

<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:** [December 20, 2021, 4:51pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/7 "2021-12-20T16:51:47Z")

</div>

That looks like it would match 4 characters, yes.  
But if that’s all you want to do you could just do this:

`/.{4}/`

---

<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 20, 2021, 5:06pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/8 "2021-12-20T17:06:21Z")

</div>

Hola

To be honest, I haven’t used RegEx on Glide APP so far but I have some Google Forms working this kind of requirement and can take a look at them and help later.

Let me see what I can get, I will be back! 😉

Saludos

---

<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 20, 2021, 8:02pm UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/9 "2021-12-20T20:02:03Z")

</div>

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)

```auto
const r = /([0-4]{4})-([0-9]{7}$)/;
return r.test(p1) 

```

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

I hope it helps!

Saludos.

---

<div class="post-metadata">

**Author:** ![Test\_Test](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/test_test/32/30930_2.png) [@Test\_Test](https://community.glideapps.com/u/Test_Test)\
**Post date:** [December 21, 2021, 9:02am UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/10 "2021-12-21T09:02:05Z")

</div>

Thanks @gvalero and @Darren_Murphy.  
Very valuable inputs. Much appreciated.

---

<div class="post-metadata">

**Author:** ![Test\_Test](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/test_test/32/30930_2.png) [@Test\_Test](https://community.glideapps.com/u/Test_Test)\
**Post date:** [December 21, 2021, 10:52am UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/11 "2021-12-21T10:52:25Z")

</div>

I’ve tried going a different path but I fear it’s oversimplified.  
What will this RegEx miss, assuming I want it to alert for anything but digits?  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/a/fa705604a4513b7b9b9de804cc475ef4a121f5d6.png)

---

<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:** [December 21, 2021, 11:16am UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/12 "2021-12-21T11:16:18Z")

</div>

`\d` usually means “any decimal digit”, which would include periods.  
You’re probably better off being a bit more explicit, something like `^[0-9]+$`

---

<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 22, 2021, 11:16am UTC](https://community.glideapps.com/t/regex-challenge-or-just-seems-that-way/36138/13 "2021-12-22T11:16:27Z")

</div>

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