Restrict input field to a very specific format of numbers and letters

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:

Input: string
Output: boolean

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
  )

2 Likes

Thanks so much for the help, @ismaen!

It looks like the first section is working:

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?

@davidpairkit - I used a somewhat brute force method. You can change the UDFs as needed.

See attached app:
Untitled_App-2023-01-11T16_17_02.743Z-full.branch.zip (33.0 KB) (DON’T USE, HAS A BUG)

1 Like

@kyung This works, thanks so much!

@davidpairkit - i think there is a bug. Use this one:

Untitled_App-2023-01-11T17_05_18.523Z-full.branch.zip (34.0 KB)

1 Like