Hi everyone - I was wondering if anyone had a working example or even a User-Defined Function for restricting an input field to a very specific format so that what the user inputs has to be in this exact format:
“A#A #A#”
where “A” means the input has to be a letter and the “#” has to be a number. Does anyone know the best way to accomplish that? Thanks!
hi @davidpairkit, I created a UDF that can do this for you, although very specific to the input of “A#A#A#”. I’m sure you can modify it in case your requirements change:
ISEMPTY(
FROM
stringItem
IN
FROM item IN SPLIT(string, "") WHERE ISEVEN(index) SELECT item
WHERE
TYPEOF(stringItem) = "number"
SELECT
stringItem
)
AND ISEMPTY(
FROM
numberItem
IN
FROM itm, idx IN SPLIT(string, "") WHERE ISODD(idx) SELECT PARSE_NUMBER(itm)
WHERE
numberItem = 0
SELECT
numberItem
)
Edit:
not sure if there is supposed to be a “space” in between the first three digits, but i just caught that. Here’s the updated UDF in case that was intenional
SPLIT(string, "")[3] = " "
AND ISEMPTY(
FROM
stringItem
IN
FROM
item
IN
FROM item2 IN SPLIT(string, "") WHERE item2 != " " SELECT item2
WHERE
ISEVEN(index)
SELECT
item
WHERE
TYPEOF(stringItem) = "number"
SELECT
stringItem
)
AND ISEMPTY(
FROM
numberItem
IN
FROM
itm,
idx
IN
FROM item3 IN SPLIT(string, "") WHERE item3 != " " SELECT item3
WHERE
ISODD(idx)
SELECT
PARSE_NUMBER(itm)
WHERE
numberItem = 0
SELECT
numberItem
)
SPLIT(string, “”)[3] = " "
AND ISEMPTY(
FROM
stringItem
IN
FROM
item
IN
FROM item2 IN SPLIT(string, “”) WHERE item2 != " " SELECT item2
WHERE
ISEVEN(index)
SELECT
item
WHERE
TYPEOF(stringItem) = “number”
SELECT
stringItem
)
But I’m having trouble with this piece:
AND ISEMPTY(
FROM
numberItem
IN
FROM
itm,
idx
IN
FROM item3 IN SPLIT(string, “”) WHERE item3 != " " SELECT item3
WHERE
ISODD(idx)
SELECT
PARSE_NUMBER(itm)
WHERE
numberItem = 0
SELECT
numberItem
)
It doesn’t seem to resolve to true because I’m ending with an array [0,0,0] from the internal FROM statement, so I’m wondering if there’s a better WHERE than “numberItem = 0” that would satisfy the logic of it needing to be a number? Any thoughts?