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:
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.
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”).
I’m almost certain this is a very basic issue that I’m missing, but that’s how “writer’s block” work…
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:
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?