If a text field has > 30 '#' then show alert
Wondering if there's a formula that will check a text field for the number of hashtags (#) and if there's more than 30, allow to pop up an alert or have field become visible alerting to the fact?
15 replies
-
I also need a way to count the number of characters in a text field (the min/max text length wont work for what I need)
-
Hi,
Try this for the first question in a formula field: you can always add if r>30 then alert("message") end
let r := 0;
let k := length(Text);
for i from 0 to k do
if substring(Text, i, i + 1) = "#" then
r := r + 1
end
end;
rAs you can see the answer on your second question is length(string)
Steven
-
@Steven, I hope you don't mind me submitting an alternative solution. I saw this post last night, but was too tired to respond.
length(replacex(Text, "[^#]", "g", ""))
When I first started learning Regex, I thought my brain was going to explode! I found it very non-intuitive, but it's very powerful. The solution I posted is really a workaround because the
extractx()
function does not work the way it should in my opinion.@Frank Böhmer, I sent an email to support for an explanation of the usage of the
extractx()
function and the response was unhelpful to say the least. I can forward that email exchange if you like. One point I would like to make is it is inconsistent to change the order of function parameters...extractx(string, regular_expression, flags, extract)
extractx(string, regular_expression, extract)
Per your documentation "extract" is the 4th parameter if "flags" is used and the 3rd parameter if "flags" isn't? Doesn't make much sense. In addition, the "flags" argument doesn't appear to work at all in the
extractx()
function. What is the "extract" argument?? I did find that "extract" does relate to groups, but does it represent anything else?? Theextractx()
function appears to mimic thematch()
function in Javascript so the following script should return an array of "#" if the extractx() intends to match Javascript'smatch()
or a string matching the result of thereplacex()
script above.length(extractx(Text, "#", "g"))
-
Sean,
No problem at all, I'm not familiar with RegEx (I know you do, an I was already kinda expecting an answer from you ) so I gave an alternative solution.
Steven.
-
Steven,
-
Sorry to jump on the end of this post, but is there a way to extract text from an array where the length of the text you want varies?
e.g i can use the concat() function to extract the full address from a location field, but is it possible to then extract only the street name and number?
-
As far as I can tell there isn't any difference between
text(Location)
andconcat(Location)
and if you test for equality you'll get true. I'm not super happy with these solutions, but there's only so much time in my day to work on it. This one simply gets the street number and name and won't work if there are any characters that aren't a number, letter or space...extractx(text(Location), "(\d+) ([\w\s]+)", "$1 - $2")
This one will catch number, letters, spaces and special characters...
extractx(text(Location), "(\d+) (.+), (?:\w+,)", "$1 - $2")
-
Another possible approach: item(split(text(Location), ", "), 0). This would fail if the string ", " appears anywhere inside the text of the location, which is not impossible, but probably quite infrequent.
-
Thank you Sean and Alain, this is the exact thing I've been looking for. I've been trying for ages before resorting to asking for help on this forum :')
I prefer Sean's 2nd formula as it also displays the 2nd line of location (but not all the time?), however it doesn't display anything if the location doesn't have a number to the address.
Alain's formula works great for what I initially asked, but I wonder if there's a way to adapt it so that it also includes the words that come after the first "," (i.e the 2nd line of location).
So from the image, if the code could also include "Glynneath" for instance
-
-
Do you mean something like:
concat(slice(split(text(Location), ", "), 0, 2))
-
Alain that is perfect! Thank you very much :D
I was just in the process of playing around with Sean's code to see if I could get it to work, but what you've given is exactly what I need.
Thank you again!
-
"e.g i can use the concat() function to extract the full address from a location field, but is it possible to then extract only the street name and number?"
-
Sorry Sean, I did address this in an earlier comment :) initially it was only the number and street name I was trying to get, but after trying your 2nd code I thought it useful to have the 2nd line of location too
-
Yep, I saw that and thought you meant apartment, suite or unit # not city name.
Content aside
- 3 yrs agoLast active
- 15Replies
- 2235Views