hi folks,
Is there a way to check for integer values for each value in an array? The array can have text or integer values.
I have already tried using like() but its not accurate as the size of the digits change i.e, double digits or triple digit numbers. Checking with tointeger() also failed as it converted text values into integers and when passed to the group() function it gave me an incorrect result.
TIA!!
Discussion posts and replies are publicly visible
Hi apoorvam
You can use Regex functions to achieve the above.
Thanks!!!
Regards
Hema
Hi - You can check the value type in Appian in following way-
typeof(123) /*returns 1, depicts the integer value*/typeof({123}) /*returns 101, depicts the array integer value*/typeof("test string") /*returns 3, depicts the string value*/typeof({"test string"}) /*returns 103, depicts the array string value*/
Run a loop on your array and check the returned value of typeof function for each iteration.
Hope this helps!
Hi Chitra Sharma
That's correct but typeof("123") will return 3 i.e., a string. typeof can't be used to find out if the input is a number or a string when enclosed in double quotes.
hi Hema
Can you help me with an example for integer values in an text array?
Please check the below sample code,
load( local!data: { "1", "Test", "1234", "Test 46 Number" }, a!forEach( items: local!data, expression: regexmatch( "[0-9]$", fv!item ) ) )
Returns true for all the integer values in the array. Hope this helps.
HI Hema,
First convert the string into Integer, if the result is not null then it mean the string has all the character alphabets.
ex
tointeger("ABX3D") return 3
tointeger("1223") return 1223
tointeger("ABC") return null
Thanks
Vinay
One simple method OOTB without the need for regex plugin, is to apply integer and reject the nulls:
fn!reject( fn!isnull, a!forEach( items: {"a",1,"b",2,"c",3}, expression: fn!tointeger(fv!item) ))
Output:
List of Number (Integer): 3 items 1 2 3
Following pattern will check for any number of digits, including none. To check for one or more digits, change * to +. To check exactly one digit, just remove the *.
*
+
regexmatch( "^[0-9]*$", "text123abc")