RegEx challenge (or just seems that way)

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.
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.

  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… :frowning: This causes the alert to fire when you enter the first (correct) character (“0”).

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

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.

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

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

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:

 \+        [[: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:]-]* 

If you really want to do it, then you’re probably better off using an existing library.

1 Like

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?

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.

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…


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

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




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! :wink:


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!



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

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?

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

1 Like

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