First letter of string

Hello,

I am posting form value of: H0009 or A00008

I want to get the first letter of the string (A or H), set it to a variable under API Execute.

Then I want to validate if it’s a letter, if not return a validation error.

Thanks

Regarding the 1st question, to obtain the first character of a string:

Set Value firstLetter = $_POST.some_form_value[0]

Don’t know the exact answer to your 2nd question, but you’d probably have to use the Regex validation

Edit: Actually, that doesn’t work, you have to do this instead:

Set Value firstLetter = $_POST.some_form_value.substr(0, 1)
1 Like

You could maybe pass the set value that is just a single letter into a validate data step:

1 Like
Set Value firstLetter = $_POST.some_form_value[0]

Where do I enter that? I am guessing set value option ?

Hi,

That looks good, yes. Does it work?

P.S.: Generally, you’d use the UI and the code section in the expression builder dialog

Yes!! Much appreciated… I am trying to get use to using it… I’ve coded for years, so it’s like a hobbit to see it, lol.

image